Site Map | Contact Info | Home  
  
 Home
 Products
 ROMHACK Toolbox
 Ordering Info
 Code Disassembly
  Bega's Battle
  Cliffhanger
  Thayer's Quest
 My Gameroom
 Links

 

 

Page1

Page2

Page3

Page4

Page5

        CALL    L1363           ; Call Speech Routine (phrase)
        LD      HL,0BE03h       ; Get MODE Register 
        SET     2,(HL)          ; Enter COMBINE MODE
        LD      B,006h          ; Loop = 6
        LD      HL,0BE31h       ; Point to combine work area
        XOR     A               ; Clear COMBINE ITEMS first
L0EC3:  LD      (HL),A          ; Clear work area
        INC     HL              ; Point to next location
        DJNZ    L0EC3           ; Loop until work area cleared       
;----------------------------------------------------
;         Clear keyboard buffer then return
;----------------------------------------------------
L0EC7:  LD      HL,0BE0Bh       ; Get Keyboard Buffer
        RES     0,(HL)          ; Clear Keyboard Buffer
        RET                     ; Return






;----------------------------------------------------
;                Combining Items
;----------------------------------------------------
L0ECD:  LD      HL,0BE0Bh       ; Check Keyboard Buffer
        RES     0,(HL)          ; Clear keyboard buffer
        CALL    L0F50           ; Point to row based on scene (C9A5)
        INC     HL              ; HL = C9A5+8*x
        LD      A,(HL)          ;
        LD      (0BE30h),A      ;
        INC     HL              ; HL = 
        LD      B,001h          ;
L0EDD:  LD      A,(0BE0Ah)      ; Get Keyboard Character
        AND     01Fh            ; Get item number
        CP      (HL)            ; Is item in table?
        JR      Z,L0F04         ; No, so skip ahead
        LD      A,(0BE30h)      ;
        CP      B               ;
        JR      Z,L0EEF         ;       
        INC     HL              ;
        INC     B               ;
        JR      L0EDD           ;       

L0EEF:  CALL    L0F50           ; Get HL pointer to row (C9A5)
        LD      A,(HL)          ; HL = C9A5+8*x
        LD      (0BC81h),A      ;
        LD      HL,0BE03h       ; Get MODE Register
        SET     0,(HL)          ; Reset Main Loop
        RES     2,(HL)          ; Cancel COMBINE MODE
        LD      DE,00032h       ; Phrase="You Don't Have That Choice Here (%)"
        CALL    L1363           ; Call Speech Routine (phrase)
        RET                     ; Return






;----------------------------------------------------
;               Speak KeyPress Item           
;----------------------------------------------------
L0F04:  LD      A,(0BE0Ah)      ; Get Keyboard Character
        SUB     041h            ; Subtract 65d
        LD      E,A             ; DE = Character Value
        LD      D,000h          ; DE = Character Value
        LD      HL,08001h       ; HL = Voice Message Table
        ADD     HL,DE           ; Index to Key Message
        EX      DE,HL           ; DE = Phrase for KeyPress
        CALL    L1363           ; Call Speech Routine (phrase)           
        LD      HL,0BE31h
        LD      A,B
        DEC     A
        JR      Z,L0F20         
        ADD     A,L
        LD      L,A
        JR      NC,L0F20       
        INC     H
L0F20:  LD      A,(HL)
        CP      001h            ; Has Item been picked up?
        RET     Z

        INC     (HL)
        LD      HL,0BE31h
        LD      A,(0BE30h)
        LD      B,A
        XOR     A
L0F2D:  CP      (HL)
        RET     Z

        INC     HL
        DJNZ    L0F2D                   
        LD      HL,0BE03h
        RES     2,(HL)
        LD      A,(IX+00Bh)
        AND     007h
        ADD     A,01Ah
        ADD     A,040h
        LD      (0BE0Ah),A
        SUB     040h
        CALL    L11DF           ; Point to Item in Inventory
        SET     1,(HL)
        LD      HL,0BE0Bh       ; Get Keyboard Buffer   
        SET     0,(HL)
        RET     


;----------------------------------------------------
;                    Unknown
;----------------------------------------------------
;         IX+0Bh =  Scene Index + something
;      Return HL =  Address to row of 8 zeros
;----------------------------------------------------
L0F50:  LD      HL,LC9A5        ; Point to start of table
        LD      A,(IX+00Bh)     ;
        AND     007h            ;
        CP      001h            ;
        RET     Z               ;
        DEC     A               ;
        LD      B,A             ; B = Loop
        LD      DE,00008h       ; Point to next row
L0F60:  ADD     HL,DE           ; Add to pointer
        DJNZ    L0F60           ; Loop until correct row is found
        RET                     ; Return






;----------------------------------------------------
;            Check if player has item
;----------------------------------------------------
L0F64:  LD      A,(0BE0Ah)      ; Get Keyboard Character
        AND     01Fh            ; Get item number
        LD      (0BE26h),A      ; Save item selected
        CALL    L11DF           ; Point to Item in Inventory
        BIT     1,(HL)          ; Check if item is in inventory
        JR      NZ,L0F79        ; Item is held so jump ahead       
        CALL    L120F           ; Tell Player they don't have said item
        JP      L0FF8           ; Skip to end
;----------------------------------------------------
;            Check if Item can be Swapped
;----------------------------------------------------
L0F79:  CALL    L11E7           ; Go to last byte of swap data
        LD      A,00Bh          ; Point to last byte
        ADD     A,L             ; Point to last byte
        LD      L,A             ; Point to last byte
        JR      NC,L0F83        ; Point to last byte       
        INC     H               ; Adjust pointer to end of row
                               
L0F83:  LD      B,006h          ; Loop = 6 possible swap senarios
L0F85:  LD      A,(HL)          ; Check byte for swap data
        CP      000h            ; Is there swap data here?
        DEC     HL              ; Data empty so skip next byte
        PUSH    HL              ; Save swap pointer
        JR      Z,L0F95         ; No data, so jump ahead and continue loop
;----------------------------------------------------
;  Swap is possible, check if correct item was used
;----------------------------------------------------               
        LD      A,(HL)          ; Get required item data
        AND     01Fh            ; Get required item value
        LD      HL,0BE26h       ; Point to item selected   
        CP      (HL)            ; Is selected item the reqired item needed?       
        JR      Z,L0F9F         ; Yes, so jump ahead and allow swap       
L0F95:  POP     HL              ; Get swap pointer
        DEC     HL              ; Go to next swap senario
        DJNZ    L0F85           ; Loop until all 6 swap senarios are checked
;----------------------------------------------------
;        Incorrect item, item has no use here
;----------------------------------------------------               
        CALL    L11FA           ; Tell player that item won't work here
        JP      L0FF8           ; Clear keyboard buffer and return

;----------------------------------------------------
;                Prepare to swap Items
;----------------------------------------------------
L0F9F:  POP     HL              ; Get swap pointer
        BIT     6,(HL)
        JR      Z,L0FD5                 
        BIT     7,(HL)
        PUSH    HL              ; Save swap pointer
        JR      Z,L0FB6                 
        LD      A,(0BE26h)      ; Get item selected
        CP      01Bh            ; Is it one of 26 items
        JR      C,L0FC8         ; No, it's more than 26       
        CALL    L102A           ; Drop combined items
        POP     HL              ; Get swap pointer
        JR      L0FD5                   

L0FB6:  LD      A,(0BE26h)      ; Get item selected
        CP      01Bh
        JR      C,L0FC3         ; Item is only dropped                 
        CALL    L0FFE
        POP     HL
        JR      L0FD5                   
L0FC3:  CALL    L11C7           ; Remove item from inventory 
        JR      L0FCB                   
L0FC8:  CALL    L11D2           ; Mark item as used
L0FCB:  LD      A,(0BE26h)      ; Get item selected
        CALL    L1224           ; Get Item's Weight
        CALL    L1230           ; Decrease Strength with item weight
        POP     HL
L0FD5:  BIT     5,(HL)
        PUSH    HL
        JR      Z,L0FEB                 
        LD      A,(IX+00Ah)     ; Get item located in room
        AND     01Fh            ; Isolate item number
        LD      HL,0BCC0h
        ADD     A,L
        LD      L,A
        JR      NC,L0FE7               
        INC     H

L0FE7:  RES     0,(HL)
        SET     1,(HL)

L0FEB:  POP     HL
        INC     HL
        LD      A,(HL)
        LD      (0BC81h),A
        LD      HL,0BE03h
        SET     4,(HL)          ; Set Audio Track 2
        SET     0,(HL)

L0FF8:  LD      HL,0BE0Bh       ; Get Keyboard Buffer
        RES     0,(HL)          ; Clear Keyboard Buffer
        RET                     ; Return






;----------------------------------------------------
;                   Unknown
;----------------------------------------------------
L0FFE:  LD      HL,0C99Eh       ;
        LD      A,(IX+00Bh)     ;
        AND     007h            ;
        SLA     A               ;
        SLA     A
        SLA     A
        ADD     A,L
        LD      L,A
        JR      NC,L1011               
        INC     H
L1011:  LD      A,(HL)
        LD      B,A
        INC     HL
L1014:  LD      A,(HL)
        PUSH    HL
        PUSH    AF
        CALL    L11DF           ; Point to Item in Inventory
        RES     1,(HL)
        SET     0,(HL)
        POP     AF
        CALL    L1224           ; Get Item's Weight
        CALL    L1230           ; Decrease Strength with item weight
        POP     HL
        INC     HL
        DJNZ    L1014
        RET     






;----------------------------------------------------
;        Drop Multiple Items that are combined
;----------------------------------------------------
L102A:  LD      HL,0C99Eh       ; Point to Item Table
        LD      A,(IX+00Bh)     ; Get row, 8 bytes per row
        AND     007h            ; Row Number between 0-7
        SLA     A               ; multiply by 2 (*2)
        SLA     A               ; multiply by 2 (*4)
        SLA     A               ; multiply by 2 (*8)
        ADD     A,L             ; Index into table
        LD      L,A             ; Index into correct row
        JR      NC,L103D        ; Check carry         
        INC     H               ; Index into row
;----------------------------------------------------
;         Drop all Items that are in table
;----------------------------------------------------
L103D:  LD      A,(HL)          ; Get Number of items from table
        LD      B,A             ; B = Number of items to drop
        INC     HL              ; Point to item in table
L1040:  LD      A,(HL)          ; Get item number from table
        PUSH    HL
        PUSH    AF
        CALL    L11DF           ; Point to Item in Inventory 
        RES     0,(HL)
        RES     1,(HL)          ; Drop item from inventory
        SET     2,(HL)
        POP     AF
        CALL    L1224           ; Get Item's Weight
        CALL    L1230           ; Decrease Strength with item weight
        POP     HL
        INC     HL              ; Next item in table
        DJNZ    01040h          ; Loop until all items dropped
        RET                     ; Return






;----------------------------------------------------
;             Using or Picking up Items
;----------------------------------------------------
L1058:  LD      A,(0BE0Ah)      ; Get Keyboard Character
        AND     01Fh            ; Isolate item number
        LD      HL,0BE26h       ; Temp save location 
        LD      (HL),A          ; Save item selected
        LD      A,(IX+00Ah)     ; Check item located in room
        AND     01Fh            ; Isolate item number
        CP      (HL)            ; Is item in room to be picked up?
        JR      NZ,L109E        ; No, so check if item is being used

;----------------------------------------------------
;            Picking up an item from a room
;----------------------------------------------------               
        BIT     0,(IX+00Dh)     ; Can we pick up items here?
        JR      Z,L1095         ; No, so skip ahead       
        CALL    L123C           ; HL = Health Pointer
        PUSH    HL              ; Save Health Pointer
;----------------------------------------------------
;     Check if player is strong enough to take item
;----------------------------------------------------
        LD      A,(0BE26h)      ; Get item selected
        CALL    L1224           ; Get Item's Weight
        LD      HL,0BCE1h       ; Get Strength 
        ADD     A,(HL)          ; Decrease player's strength
        LD      (0BE18h),A      ; Save new strength temporarily
        POP     HL              ; Point to Health
        LD      A,(HL)          ; Get Health
        LD      HL,0BE18h       ; Point to new strength
        CP      (HL)            ; Are they strong enough to pick up item?
        JP      C,L11A6         ; No, the player must drop something
        LD      A,(0BE18h)      ; Get new stregth
        LD      (0BCE1h),A      ; Save player's adjusted strength
        LD      A,(0BE26h)      ; Get item selected
        CALL    L11BF           ; Put item in inventory

L1095:  LD      A,(IX+00Ch)     ; Get next scene
        LD      (0BC81h),A      ; Store Scene Index
        JP      L1199           ; Update then return



;----------------------------------------------------
;           Use an Item to get another Item
;----------------------------------------------------
L109E:  LD      A,(0BE26h)      ; Get item selected
        CALL    L11DF           ; Point to Item in Inventory
        BIT     1,(HL)          ; Is item in inventory?
        JR      NZ,L10AE        ; Yes, so skip ahead       
        CALL    L120F           ; Tell Player they don't have said item
        JP      L11A0           ; Clear Keyboard Buffer and Return
;----------------------------------------------------
;          Get Item Swap Properties from table
;----------------------------------------------------
L10AE:  LD      HL,LC743        ; Start of Item Swap table
        LD      A,(IX+00Ah)     ; Get item located in room
        AND     01Fh            ; Get item number
        CP      001h            ; Is it the first item?
        JR      Z,L10C2         ; Yes, so row is set       
        DEC     A               ; Subtract 1
        LD      B,A             ; Loop = Item row
        LD      DE,00006h       ; Skip row (6 bytes)
L10BF:  ADD     HL,DE           ; Point to next row
L10C0:  DJNZ    L10BF           ; Loop until Item Use row found     
;----------------------------------------------------
;            Check if Item can be Swapped
;----------------------------------------------------
L10C2:  LD      A,005h          ; Go to last byte of swap data
        ADD     A,L             ; Point to last byte
        LD      L,A             ; Point to last byte
        JR      NC,L10C9        ; Point to last byte
        INC     H               ; Point to last byte

L10C9:  LD      B,003h          ; Loop = 3 possible swap senarios
L10CB:  LD      A,(HL)          ; Check byte for swap data
        CP      000h            ; Is there swap data here?
        JR      NZ,L10D4        ; Yes, so skip ahead and check for item match
        DEC     HL              ; Data empty so skip next byte
        PUSH    HL              ; Save swap pointer
        JR      L10DF           ; Jump ahead and continue loop
;----------------------------------------------------
;  Swap is possible, check if correct item was used
;----------------------------------------------------
L10D4:  DEC     HL              ; Point to required item data
        LD      A,(HL)          ; Get required item data
        AND     01Fh            ; Get required item value
        PUSH    HL              ; Save swap pointer
        LD      HL,0BE26h       ; Point to item selected
        CP      (HL)            ; Is selected item the reqired item needed?
        JR      Z,L10E9         ; Yes, so jump ahead and allow swap       
L10DF:  POP     HL              ; Get swap pointer
        DEC     HL              ; Go to next swap senario
        DJNZ    L10CB           ; Loop until all 3 swap senarios are checked
;----------------------------------------------------
;       Incorrect item, item has no use here
;----------------------------------------------------               
        CALL    L11FA           ; Tell player that item won't work here
        JP      L11A0           ; Clear Keyboard Buffer and Return

;----------------------------------------------------
;                Prepare to swap Items
;----------------------------------------------------
L10E9:  POP     HL              ; Get swap pointer
        BIT     6,(HL)          ; Is it a 1-for-1 swap?
        JP      Z,L115E         ; Yes, so jump ahead
        BIT     5,(HL)          ; Is it a 2-for-1 swap?
        JR      NZ,L110E        ; Yes, so jump ahead
               
        PUSH    HL              ; Save swap pointer
        CALL    L11C7           ; Remove item from inventory
        LD      A,(0BE26h)      ; Get item selected
        CALL    L1224           ; Get Item's Weight
        CALL    L1230           ; Decrease Strength with item weight
        POP     HL              ; Get swap pointer
        BIT     7,(HL)          ; Does the item expire after use?
        JP      Z,L1194         ; No, so skip ahead and play successful swap scene
;----------------------------------------------------
;        Mark item as used, play successful scene
;----------------------------------------------------
        PUSH    HL              ; Save swap pointer
        CALL    L11D2           ; Mark item as used 
        POP     HL              ; Get swap pointer
        JP      L1194           ; Play successful swap scene

;----------------------------------------------------
;                       
;----------------------------------------------------
L110E:  PUSH    HL              ; Save swap pointer
        LD      A,(0BE26h)      ; Get item selected
        CALL    L1224           ; Get Item's Weight
        LD      (0BE18h),A
        LD      A,(0BCE1h)
        LD      HL,0BE18h
        SBC     A,(HL)
        LD      (0BE18h),A
        LD      A,(IX+00Ah)     ; Get item located in room
        AND     01Fh            ; Isolate item number
        CALL    L1224           ; Get Item's Weight
        LD      HL,0BE18h       ; Point to player strength
        ADD     A,(HL)          ; Add weight to player's strength
        LD      (0BE18h),A      ; Save player's strength temporarily
        CALL    L123C           ; HL = Health Pointer
        LD      A,(HL)          ; Get Health
        LD      HL,0BE18h       ; Point to new strength
        CP      (HL)            ; Are they strong enough to pick up item?
        JR      NC,L113F        ; Yes, so skip ahead         
        POP     HL              ; Get swap pointer
        JP      L11A6           ; Tell player to drop something before picking up

L113F:  LD      A,(0BE18h)
        LD      (0BCE1h),A
        CALL    L11C7           ; Remove item from inventory
        POP     HL
        BIT     7,(HL)
        JR      Z,L1152                 
        PUSH    HL
        CALL    L11D2           ; Mark item as used
        POP     HL              ; Get swap pointer
;----------------------------------------------------
;            Put new item into inventory
;----------------------------------------------------
L1152:  PUSH    HL              ; Save swap pointer
        LD      A,(IX+00Ah)     ; Get item located in room
        AND     01Fh            ; Isolate item number
        CALL    L11BF           ; Put item in inventory
        POP     HL              ; Get swap pointer
        JR      L1194           ; Play successful swap scene       



;----------------------------------------------------
;                       
;----------------------------------------------------                       
L115E:  BIT     5,(HL)
        JR      Z,L1194                 
        PUSH    HL              ; Save swap pointer
        LD      A,(0BCE1h)      ; Get Strength
        LD      (0BE18h),A      ; Save Strength temporarily
        LD      A,(IX+00Ah)     ; Get item located in room
        AND     01Fh            ; Isolate item number
        CALL    L1224           ; Get Item's Weight
        LD      HL,0BE18h       ; Point to temporary strength
        ADD     A,(HL)          ; Add to player's strength
        LD      (0BE18h),A      ; Save calculated strength
        CALL    L123C           ; HL = Health Pointer
        LD      A,(HL)
        LD      HL,0BE18h
        CP      (HL)
        JR      NC,L1185               
        POP     HL
        JR      L11A6           ; Tell player to drop something before picking up       
L1185:  LD      A,(0BE18h)
        LD      (0BCE1h),A
        LD      A,(IX+00Ah)
        AND     01Fh
        CALL    L11BF           ; Put item in inventory
        POP     HL              ; Get swap pointer
;----------------------------------------------------
;           Play successful swap scene
;----------------------------------------------------
L1194:  INC     HL              ; Point to swap scene byte
        LD      A,(HL)          ; Get swap scene
        LD      (0BC81h),A      ; Store new Scene Index
L1199:  LD      HL,0BE03h       ; Get MODE Register
        SET     0,(HL)          ;
        SET     4,(HL)          ; Set Audio Track 2
L11A0:  LD      HL,0BE0Bh       ; Get Keyboard Buffer
        RES     0,(HL)          ; Clear Keyboard Buffer
        RET                     ; Return






;----------------------------------------------------
; Tell player to drop something before picking up
;----------------------------------------------------
L11A6:  CALL    L136C           ; Clear Speech Buffer
        LD      DE,00039h       ; Phrase = "(%) You Must Drop Something To Get"
        CALL    L1383           ; Get Phrase from Table
        LD      A,(IX+00Ah)     ; Get item located in room
        AND     01Fh            ; Get item number
        LD      E,A             ; Turn item number into phrase
        LD      D,080h          ; Phrase = Item Name
        CALL    L1383           ; Get Phrase from Table
        CALL    L21C1           ; Command Speech Chip to speak buffer
        JR      L11A0           ; Clear Keyboard Buffer and Return         


;----------------------------------------------------
;              Put item in inventory
;----------------------------------------------------
L11BF:  CALL    L11DF           ; Point to Item in Inventory
        SET     1,(HL)          ; Put item into inventory
        RES     0,(HL)          ; ??
        RET                     ; Return


;----------------------------------------------------
;             Remove item from inventory
;----------------------------------------------------
L11C7:  LD      A,(0BE26h)      ; Get item selected
        CALL    L11DF           ; Point to Item in Inventory
        RES     1,(HL)          ; Remove item from inventory
        SET     0,(HL)          ; ??
        RET                     ; Return

;----------------------------------------------------
;                Mark item as used
;----------------------------------------------------
L11D2:  LD      A,(0BE26h)      ; Get item selected
        CALL    L11DF           ; Point to Item in Inventory
        SET     2,(HL)          ; Mark item as used
        RES     0,(HL)          ; ??
        RES     1,(HL)          ; Remove item from inventory
        RET                     ; Return



;----------------------------------------------------
;            Point to Item in Inventory
;----------------------------------------------------
;                A = Item Number
;      Return:  HL = BC9F + A
;----------------------------------------------------
L11DF:  LD      HL,0BC9Fh       ;
        ADD     A,L             ;
        LD      L,A             ;
        RET     NC              ;
        INC     H               ;
        RET                     ;
                               




;----------------------------------------------------
;          Get row data from C7DF ROM
;----------------------------------------------------
;       Return HL = Pointer to row data
;----------------------------------------------------
L11E7:  LD      HL,LC7DF        ; Get start of table
        LD      A,(IX+00Ah)     ; Get item located in room
        AND     01Fh            ; Get item number
        CP      000h            ; Is there an item in the room?
        RET     Z               ; No item in room so leave

        LD      B,A             ; Loop = Item row number 
        LD      DE,0000Ch       ; Skip one row of data
L11F6:  ADD     HL,DE           ; Go to next row
        DJNZ    L11F6           ; Loop until correct row is reached       
        RET                     ; Return



;----------------------------------------------------
;       Tell player that item won't work here
;----------------------------------------------------
L11FA:  CALL    L136C           ; Clear Speech Buffer
        LD      A,(0BE26h)      ; Get item trying to be used
L1200:  LD      E,A             ; Make item into word
        LD      D,080h          ; Setup word to speak
        CALL    L1383           ; Get Phrase from Table
        LD      DE,00031h       ; Phrase = "Won't Work Here (%)"
        CALL    L1383           ; Get Phrase from Table
        JP      L21C1           ; Command Speech Chip to speak buffer





;----------------------------------------------------
;       Tell player they don't have said item
;----------------------------------------------------
L120F:  CALL    L136C           ; Clear Speech Buffer
        LD      DE,00030h       ; Phrase = "Sorry (%) You Don't Have"
        CALL    L1383           ; Get Phrase from Table
        LD      A,(0BE26h)      ; Get Item trying to be used
        LD      E,A             ; Make item into word
        LD      D,080h          ; Set up Word to speak
        CALL    L1383           ; Get Phrase from Table
        JP      L21C1           ; Command Speech Chip to speak buffer






;----------------------------------------------------
;             Get Item's Weight
;----------------------------------------------------
;             A = Item Number (1-26)
;----------------------------------------------------
;      Return A = Item Weight (0-7)
;----------------------------------------------------
L1224:  LD      HL,0C95Eh       ; Point to Item Property Table
        ADD     A,L             ; Add item pointer
        LD      L,A             ; Add item pointer
        JR      NC,L122C        ; Jump on overflow       
        INC     H               ; Add item pointer
L122C:  LD      A,(HL)          ; Get item property
        AND     007h            ; Get item's weight
        RET                     ; Return





;----------------------------------------------------
;         Decrease Strength with item weight
;----------------------------------------------------
;             A = Item Weight (0-7)
;----------------------------------------------------
L1230:  LD      HL,0BE18h       ; Item Weight
        LD      (HL),A          ; Store Item Weight
        LD      A,(0BCE1h)      ; Get Strength
        SBC     A,(HL)          ; Subtract Weight from Strength
        LD      (0BCE1h),A      ; Save Strength
        RET                     ; Return





;----------------------------------------------------
;                    Unknown
;----------------------------------------------------
;          (BCE0)     Health index
;          Return HL  Pointer to Health Value
;----------------------------------------------------
L123C:  LD      HL,0C97Eh       ; Point to Health Table
        LD      A,(0BCE0h)      ; A = Health setting
        ADD     A,L             ; Add to pointer
        LD      L,A             ; Point to table
        RET     NC              ; Check carry
        INC     H               ; Point to table
        RET                     ; Return



    org  01247h
;----------------------------------------------------
;               Initialize Speech Chip
;----------------------------------------------------
L1247:  LD      (0A60Ah),HL     ; Erase any pending data
        LD      (0A608h),HL     ; Erase any pending data
        LD      A,080h          ; Control Code 80?
        OUT     (003h),A        ; Set Speech Chip Register3
        LD      A,0C0h          ; Control Code C0?
        OUT     (000h),A        ; Set Speech Chip Register0
        LD      A,07Bh          ; Control Code 7B?
        OUT     (003h),A        ; Set Speech Chip Register3
        LD      A,0E6h          ; Initial Filter Frequency (0E6h)
        OUT     (004h),A        ; Set Speech Chip Register4
        LD      A,090h          ; Control Code 90?
        OUT     (002h),A        ; Set Speech Chip Register2
        LD      A,046h          ; Initial Inflection (046h)   
        OUT     (001h),A        ; Set Speech Chip Register1
        XOR     A               ; Control Code = PAUSE (00h)
        OUT     (000h),A        ; Set Speech Chip Register0
        RET                     ; Return






;----------------------------------------------------
;   Interrupt function to send data to Speech Chip
;----------------------------------------------------
;   A60A is incremented here in the interrupt
;   Once A60A is equal to A608 then we're finished
;----------------------------------------------------
L1269:  LD      A,(0A608h)      ; Get number of Control Codes to be sent
        LD      HL,(0A60Ah)     ; Get number of codes that have already been sent
        CP      L               ; Are there more control codes to send?
        JR      C,L1288         ; No control codes remaining, skip ahead
        JR      Z,L1288         ; No control codes remaining, skip ahead
;----------------------------------------------------
;         Send bytes to Speech Chip registers
;----------------------------------------------------
;        OUT (004h)  <- (A000) Filter Frequency  (ie E7h)
;        OUT (003h)  <- (A100) <AA>  Punctuation Control Codes  (ie 54h,74h)
;        OUT (002h)  <- (A200) <RI>  Character Control Codes (ie A8h)
;        OUT (001h)  <- (A300) <IO>  (ie 68h)
;        OUT (000h)  <- (A400) <OUT> Phoneme Codes (ie D,AH1,UH1)
;----------------------------------------------------             
        LD      C,004h          ; Output to Speech Registers 4,3,2,1,0
        LD      B,005h          ; Loop = 5 registers
L1278:  LD      A,(HL)          ; Get character/code from message
        OUT     (C),A           ; Send character/code to Speech register
        INC     H               ; Next character/code (A000,A100,A200,...)
        DEC     C               ; Next register (port)
        DJNZ    L1278           ; Loop until all registers are written       
        LD      A,H             ; Get register
        SUB     005h            ; Go back to first register (A0xx)
        LD      H,A             ; Point to byte just sent
        INC     HL              ; Increment to next byte
        LD      (0A60Ah),HL     ; Save number of bytes sent
        RET                     ; Return
;----------------------------------------------------
; Data packet sent so turn off Speech Chip interrupt
;----------------------------------------------------
L1288:  LD      A,080h          ; Raise Control bit in Register3
        OUT     (003h),A        ; Send to Speech Chip Register3
        XOR     A               ; Control Code 00?
        OUT     (000h),A        ; Send to Speech Chip Register0
        LD      A,070h          ; Lower Control bit in Register3
        OUT     (003h),A        ; Send to Speech Chip Register3
        XOR     A               ; Control Code 00?
        OUT     (000h),A        ; Send to Speech Chip Register0
        RET                     ; Return





;----------------------------------------------------
;            Phrase and Word Indexes
;----------------------------------------------------
L1297:  .word  0686Bh    ; Phrase Index
L1299:  .word  05C7Bh    ; Word Index




;----------------------------------------------------
;       Table of 1 of 4 Random Phrases
;----------------------------------------------------
L129B:  DB  000h001h002h003h  ; Type in Name
L129F:  DB  004h005h006h007h  ; Name Too Long
L12A3:  DB  008h009h00Ah00Bh  ; Did I Say Your Name Right?
L12A7:  DB  00Ch00Dh00Dh00Fh  ; Just Letters
L12AB:  DB  010h011h012h013h  ; Enter Yes or No 
L12AF:  DB  014h017h016h015h  ; Act lively
L12B3:  DB  018h019h01Ah01Bh  ; Retype in Name
L12B7:  DB  01Ch01Dh01Eh01Fh  ; Empty-Handed
L12BB:  DB  02Ah02Bh02Ch02Ch  ; No Pointer
L12BF:  DB  02Dh02Dh02Eh02Fh  ; Try A Different Spelling
L12C3:  DB  032h03Dh03Eh01Bh  ; Bad Choice
L12C7:  DB  066h067h068h08Fh  ; Name sounds French
L12CB:  DB  05Eh09Ah09Bh09Ch  ; Nice To Have You Here Again (#)





;----------------------------------------------------
;     Subtract values for Speaking Score
;----------------------------------------------------
L12CF:  DB  098h096h080h  ; 10,000,000
        DB  00Fh042h040h  ;  1,000,000
        DB  001h086h0A0h  ;    100,000
        DB  000h027h010h  ;     10,000
        DB  000h003h0E8h  ;      1,000
        DB  000h000h064h  ;        100
        DB  000h000h00Ah  ;         10
        DB  000h000h001h  ;          1





;----------------------------------------------------
;      Speak Score "Teen" Word Pointer Table
;----------------------------------------------------
L12E7:   DB  02Bh  ; "Thir-"
         DB  004h  ; "Four-"
         DB  02Ch  ; "Fif-"