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

;----------------------------------------------------
;                    Start SEARCH
;----------------------------------------------------
        LD      A,00Ah          ; Command = SEARCH
        CALL    GetCommand      ; Get LDPlayer Command Byte
        CALL    L1E80           ; Send $FF then Command byte to LDPlayer

;----------------------------------------------------
;            Wait for SEARCH to complete
;----------------------------------------------------
        LD      HL,0A79Ah       ; Get LDPlayer Status Byte
        BIT     3,(HL)          ; Check LDPLAYER TYPE
        JP      Z,L1E67         ; PR-7820 selected so skip ahead
        PUSH    BC              ; Save BC Register
;----------------------------------------------------
;            LD-V1000:  SEARCH wait
;----------------------------------------------------
        LD      B,000h          ; Start SEARCH wait timer
L1DF4:  IN      A,(0F1h)        ; Get LDPlayer Status
        BIT     6,A             ; Is LDPlayer READY?
        JP      NZ,L1DF4        ; Wait here until data arrives
        IN      A,(0F0h)        ; Get LDPlayer Data Byte 
        CP      0D0h            ; Is SEARCH FINISHED?
        JR      NZ,L1E04        ; No, so skip ahead
        POP     BC              ; SEARCH done so restore BC Register
        JR      L1E54           ; Wait for STATUS toggle
;----------------------------------------------------
;     Test for SEARCH ERROR or excessive wait time
;----------------------------------------------------
L1E04:  CP      090h            ; Is there a SEARCH ERROR?
        JR      Z,L1E1A         ; Yes, so handle error
        INC     B               ; Count time waiting for SEARCH to complete
        LD      HL,0A787h       ; Get Number of SEARCH Retries
        LD      A,000h          ; Check number of retries
        CP      (HL)            ; Have we retried the SEARCH yet? 
        JR      Z,L1E15         ; No, so wait longer       
        LD      A,066h          ; Time to Wait = 66h
        JR      L1E17           ; Check wait time       
L1E15:  LD      A,0FFh          ; Time to Wait = FFh
L1E17:  CP      B               ; Have we waited long enough for SEARCH?
        JR      NZ,L1E4A        ; No, wait longer.  Loop back.       

;----------------------------------------------------
;       Retry SEARCH if SEARCH ERROR encounter
;----------------------------------------------------
L1E1A:  LD      HL,0A787h       ; Get Number of SEARCH Retries
        INC     (HL)            ; Increment number of retries
        LD      A,003h          ; Check for 3 retries
        CP      (HL)            ; Have we retried 3 times yet?
        JR      NZ,L1E3E        ; Not yet, so retry again
             
;----------------------------------------------------
; LDPlayer FAULT occured, Check if Frame Number Valid 
;----------------------------------------------------                 
        LD      C,(IY+003h)     ; BC = Scene Frame Number
        LD      B,(IY+004h)     ; BC = Scene Frame Number
        LD      HL,07BD4h       ; Check if frame number > 31700
        AND     A               ; Set Carry
        SBC     HL,BC           ; Compare Frame Number
        JP      C,L0000         ; Frame Number too high, so reset machine
        LD      HL,00064h       ; Check if frame number < 100
        AND     A               ; Set Carry
        SBC     HL,BC           ; Compare Frame Number
        JP      NC,L0000        ; Frame Number too low, so reset machine
        POP     BC              ; Restore BC Register
        JR      L1E54           ; Just start disc wherever it's at

;----------------------------------------------------
;        Retry SEARCH with Frame Number + 1
;----------------------------------------------------
L1E3E:  LD      HL,0A7B5h       ; Point to Frame Number
        LD      A,(HL)          ; Get Frame Number for addition
        ADD     A,001h          ; Add 1 to frame
        DAA                     ; Add decimal 1 to frame number
        LD      (HL),A          ; Store new frame
        POP     BC              ; Restore BC Register
        JP      L1DA3           ; Try SEARCH again

;----------------------------------------------------
;       LD-V1000 wait for STATUS Bit
;----------------------------------------------------
L1E4A:  IN      A,(0F1h)        ; Get LDPlayer Status
        BIT     6,A             ; Is LDPlayer READY?
        JP      Z,L1E4A         ; Wait here until SEARCH is finished
        JP      L1DF4           ; Loop back and wait for byte from LDPlayer

;----------------------------------------------------
;       Frame found, now send PLAY Command
;----------------------------------------------------
L1E54:  LD      HL,0A791h       ; Get LDPlayer Control Register
        SET     2,(HL)          ; Mark search as completed
        BIT     4,(HL)          ; Is it Freeze Frame?
        JP      Z,L1E66         ; Yes, so skip PLAY Command
        LD      A,00Bh          ; Get PLAY Command
        CALL    GetCommand      ; Get LDPlayer Command Byte
        CALL    L1E80           ; Send $FF then Command byte to LDPlayer
L1E66:  RET                     ; Return

;----------------------------------------------------
;            PR-8210:  SEARCH wait
;----------------------------------------------------
L1E67:  IN      A,(0F1h)        ; Get LDPlayer Status
        BIT     7,A             ; Is LDPlayer READY?
        JP      NZ,L1E67        ; Wait here until SEARCH finished
        JP      L1E54           ; Frame found so continue








;----------------------------------------------------
;         Get LDPlayer Command from Table
;----------------------------------------------------
;         A = index to command
;     $1F65 = Start of Command Table (CommandTable)
;     $A784 = Gets loaded with Command Code
;----------------------------------------------------
GetCommand:
        PUSH    HL              ; Save HL Register
        LD      HL,01F65h       ; Load HL with pointer to Command Table
        ADD     A,L             ; A = Index to add to Command Table
        LD      L,A             ; Add Index
        JR      NC,L1E7A        ; Check carry after add
        INC     H               ; Increment Command Table pointer if carry set
L1E7A:  LD      A,(HL)          ; Get Command Byte from Command Table
        LD      (0A784h),A      ; Store Command Byte
        POP     HL              ; Restore HL Register
        RET                     ; Return





;----------------------------------------------------
;      Send command with $FF to LDPlayer
;----------------------------------------------------
L1E80:  PUSH    HL              ; Temporarily save HL Register
        LD      HL,0A79Ah       ; Get LDPlayer Status Byte
        BIT     3,(HL)          ; Check LDPLAYER TYPE
        POP     HL              ; Restore HL Register
        JP      Z,L1ED8         ; PR-7820 selected so skip ahead
        PUSH    HL              ; Save HL Register
        PUSH    BC              ; Save BC Register
        LD      A,(0A784h)      ; Get Command from A784h
        LD      B,A             ; Store Command in B temporarily
        LD      A,0FFh          ; Load an FFh
        LD      (0A784h),A      ; Store FFh in Command spot
        CALL    L1EA2           ; Send FFh to LDPlayer
        LD      A,B             ; Restore Command from B
        LD      (0A784h),A      ; Store Command in A784h
        CALL    L1EA2           ; Send Command to LDPlayer
        POP     BC              ; Restore BC Register
        POP     HL              ; Restore HL Register                     
        RET                     ; Return





;----------------------------------------------------
;       Output Command to LDPlayer (LD-V1000)
;----------------------------------------------------
L1EA2:  PUSH    HL              ; Save HL Register
        LD      A,(0A784h)      ; Load Command byte
        OUT     (0F4h),A        ; Send Command byte to LDPlayer

L1EA8:  IN      A,(0F1h)        ; Get LDPlayer Register
        BIT     6,A             ; Test Command Strobe
        JP      NZ,L1EA8        ; Loop until Command Strobe goes low

L1EAF:  IN      A,(0F1h)        ; Get LDPlayer Register
        BIT     6,A             ; Test Command Strobe
        JP      Z,L1EAF         ; Loop until Command Strobe goes high
;----------------------------------------------------
;        Set LDPlayer Communication Bus to Output
;----------------------------------------------------
        LD      HL,0A783h       ; Use LDPlayer Hardware Register
        SET     5,(HL)          ; Set LDPlayer data bus as Output
        RES     7,(HL)          ; Clear INT/EXT
        LD      A,(HL)          ; Update LDPlayer Hardware Register
        OUT     (0F5h),A        ; Write to Hardware
;----------------------------------------------------
;          Wait until LDPlayer is not BUSY
;----------------------------------------------------
L1EC0:  IN      A,(0F1h)        ; Get LDPlayer Register
        BIT     7,A             ; Check if LDPlayer busy
        JP      NZ,L1EC0        ; Wait until LDPlayer is not busy
L1EC7:  IN      A,(0F1h)        ; Get LDPlayer Register
        BIT     7,A             ; Check if LDPlayer busy
        JP      Z,L1EC7         ; Wait until LDPlayer is not busy
;----------------------------------------------------
;      Return LDPlayer Communication Bus to Input
;----------------------------------------------------
        LD      HL,0A783h       ; Use LDPlayer Hardware Register
        RES     5,(HL)          ; Set LDPlayer data bus as Input
        LD      A,(HL)          ; Update LDPlayer Hardware Register
        OUT     (0F5h),A        ; Write to Hardware

        POP     HL              ; Restore HL Register
        RET                     ; Return






;----------------------------------------------------
;       Send command with $FF  (PR-7820)
;----------------------------------------------------
L1ED8:  PUSH    HL              ; Save HL Register
        LD      HL,0A783h       ; Use LDPlayer Hardware Register
        RES     7,(HL)          ; Clear INT/EXT
        LD      A,(HL)          ; Update LDPlayer Hardware Register
        OUT     (0F5h),A        ; Write to Hardware
        LD      A,(0A784h)      ; Get Command from A784h
        OUT     (0F4h),A        ; Send Command byte to LDPlayer
;----------------------------------------------------
;     Return LDPlayer Communication Bus to Output
;----------------------------------------------------
        LD      HL,0A783h       ; Use LDPlayer Hardware Register
        SET     5,(HL)          ; Set LDPlayer data bus as Output
        LD      A,(HL)          ; Update LDPlayer Hardware Register
        OUT     (0F5h),A        ; Write to Hardware
;----------------------------------------------------
;         Press ENTER on LDPlayer then delay
;----------------------------------------------------
        RES     6,(HL)          ; Press ENTER
        LD      A,(HL)          ; Update LDPlayer Hardware Register
        OUT     (0F5h),A        ; Write to Hardware

        CALL    L1F0B           ; Call Delay (0DF6)
;----------------------------------------------------
;        Release ENTER on LDPlayer then delay
;----------------------------------------------------
        LD      HL,0A783h       ; Use LDPlayer Hardware Register
        SET     6,(HL)          ; Release ENTER
        LD      A,(HL)          ; Update LDPlayer Hardware Register
        OUT     (0F5h),A        ; Write to Hardware

        CALL    L1F0B           ; Call Delay (0DF6)
;----------------------------------------------------
;      Return LDPlayer Communication Bus to Input
;----------------------------------------------------
        LD      HL,0A783h       ; Use LDPlayer Hardware Register
        RES     5,(HL)          ; Set LDPlayer data bus as Input
        LD      A,(HL)          ; Update LDPlayer Hardware Register
        OUT     (0F5h),A        ; Write to Hardware
        POP     HL              ; Restore HL Register
        RET                     ; Return



;----------------------------------------------------
;          Delay for 0DF6h
;----------------------------------------------------
L1F0B:  LD      DE,0FFFFh       ; DE = -1
L1F0E:  LD      HL,00DF6h       ; Timer = 0DF6h
L1F11:  ADD     HL,DE           ; Subtract 1 from timer
        JR      C,L1F11         ; Loop until timer expired       
        RET                     ; Return



;----------------------------------------------------
;          Send PAUSE command to LDPlayer
;----------------------------------------------------
L1F15:  LD      A,00Ch          ; Get PAUSE Command
        CALL    GetCommand      ; Get LDPlayer Command Byte
        CALL    L1E80           ; Send $FF then Command byte to LDPlayer
        RET                     ; Return



;----------------------------------------------------
;              Send PLAY command to LDPlayer
;----------------------------------------------------
SendPlay:
L1F1E:  LD      A,00Bh          ; Get PLAY Command
        CALL    GetCommand      ; Get LDPlayer Command Byte
        CALL    L1E80           ; Send $FF then Command byte to LDPlayer
        RET                     ; Return


;----------------------------------------------------
;           Send REJECT command to LDPlayer
;----------------------------------------------------
L1F27:  LD      A,01Bh          ; Get REJECT Command
        CALL    GetCommand      ; Get LDPlayer Command Byte
        CALL    L1E80           ; Send $FF then Command byte to LDPlayer
        RET                     ; Return


;----------------------------------------------------
;        Send (unknown) command to LDPlayer
;----------------------------------------------------
L1F30:  LD      HL,0A79Ah       ; Get LDPlayer Status Byte 
        BIT     3,(HL)          ; Check LDPLAYER TYPE
        JP      Z,L1F41         ; PR-7820 selected so skip ahead
        LD      A,014h          ; Get <> Command
L1F3A:  CALL    GetCommand      ; Get LDPlayer Command Byte
        CALL    L1E80           ; Send $FF then Command byte to LDPlayer
        RET                     ; Return;

;----------------------------------------------------
;        Send (unknown) command to LDPlayer
;----------------------------------------------------
L1F41:  LD      A,017h          ; Get <> Command
        JP      L1F3A           ; Jump back and send command
        LD      HL,0A79Ah       ; Get LDPlayer Status Byte 
        BIT     3,(HL)          ; Check LDPLAYER TYPE
        JP      Z,L1F57         ; PR-7820 selected so skip ahead
        LD      A,015h          ; Get <> Command
L1F50:  CALL    GetCommand      ; Get LDPlayer Command Byte
        CALL    L1E80           ; Send $FF then Command byte to LDPlayer
        RET                     ; Return
         
;----------------------------------------------------
;        Send (unknown) command to LDPlayer
;----------------------------------------------------
L1F57:  LD      A,018h          ; Get <> Command
        JP      L1F50           ; Go back and send command to LDPlayer
        LD      A,00Fh          ; Get <> Command
        CALL    GetCommand      ; Get LDPlayer Command Byte
        CALL    L1E80           ; Send $FF then Command byte to LDPlayer
        RET                     ; Return





;----------------------------------------------------
;           Table of LDPlayer Commands
;----------------------------------------------------
CommandTable:
                .byte   03Fh        ; A=00  0
                .byte   00Fh        ; A=01  1
                .byte   08Fh        ; A=02  2
                .byte   04Fh        ; A=03  3
                .byte   02Fh        ; A=04  4
                .byte   0AFh        ; A=05  5
                .byte   06Fh        ; A=06  6
                .byte   01Fh        ; A=07  7
                .byte   09Fh        ; A=08  8
                .byte   05Fh        ; A=09  9
                .byte   0F7h        ; A=0A  SEARCH
                .byte   0FDh        ; A=0B  PLAY
                .byte   0FBh        ; A=0C  PAUSE (STOP)
                .byte   0DFh        ; A=0D  (unknown)
                .byte   0EFh        ; A=0E  (unknown)
                .byte   0F1h        ; A=0F  DISPLAY
                .byte   0F4h        ; A=10  AUDIO 1
                .byte   0FCh        ; A=11  AUDIO 2
                .byte   0A3h        ; A=12  X1 FORWARD
                .byte   0A0h        ; A=13  X0 FORWARD (STOP)
                .byte   0CDh        ; A=14  DISPLAY DISABLE
                .byte   0CEh        ; A=15  DISPLAY ENABLE
                .byte   0FAh        ; A=16  (unknown)
                .byte   0E1h        ; A=17  (unknow)
                .byte   0E0h        ; A=18  (unknown)
                .byte   0A1h        ; A=19  X1/4 FORWARD
                .byte   0A2h        ; A=1A  X1/2 FORWARD
                .byte   0F9h        ; A=1B  REJECT
 




;----------------------------------------------------
;          Diagnostic Test Addresses
;---------------------------------------------------- 
L1F81:   .word   02041h   ; RAM Test
         .word   0208Ah   ; ROM Test   
         .word   020E1h   ; Scoreboard Test
         .word   0211Ah   ; Keyboard Test
         .word   0214Ah   ; Communications Link Test
         .word   02151h   ; Monitor Test 
         .word   01F9Bh   ; Begin Diagnostics
         
;----------------------------------------------------
;                  unknown
;---------------------------------------------------- 
L1F90:   .byte   060h071h060h071h060h071h
         .byte   060h071h060h071h060h071h





;----------------------------------------------------
;                Begin Diagnostics
;---------------------------------------------------- 
L1F9B:  LD      DE,000A3h       ; Load Phrase (A3) "Diagnostic Tests"
        CALL    L1363           ; Call Speech Routine (phrase)           
        CALL    L210C           ; Blank out Scoreboard
        CALL    L1FD3           ; Check Keyboard for "M" pressed
        JR      C,L1FEE         ; If pressed jump to MENU MODE       
        LD      BC,01F81h       ; BC = Pointer to first Test
        LD      DE,(0C008h)     ; Get Frame Number, "Begin Diagnostics, RAM Test in Progress"
L1FB0:  LD      A,(BC)          ; A = Address Pointer
        LD      L,A             ; L = A
        INC     BC              ; Point to next byte 
        LD      A,(BC)          ; A = Next Byte 
        LD      H,A             ; H = A, HL = Test Address
        INC     BC              ; Increment Pointer to next test
        PUSH    DE              ; Save DE Register
        PUSH    BC              ; Save BC Register
        PUSH    HL              ; Save HL Register
        CALL    L1C57           ; PAUSE on Frame Number, "Begin Diagnostics"
        POP     HL              ; Restore HL Register
        LD      DE,01FC2h       ; DE = Return Address
        PUSH    DE              ; Store Return Address once test is complete
;----------------------------------------------------
        JP      (HL)            ; Jump to Test Routine
;----------------------------------------------------


L1FC2:  CALL    L1FD3           ; Check Keyboard for "M" pressed
        POP     BC              ; Restore BC Register (IY)
        POP     DE              ; Restore DE Register (DE)
        JR      C,L1FEE         ; If "M" pressed jump to MENU MODE       
        LD      A,(0C00Ah)      ; A = 0Ah, Add 0Ah to Return Address
        ADD     A,E             ; A = A + E      (DE = DE + 0Ah)
        LD      E,A             ; E = A
        JR      NC,L1FB0        ; Check if carry is set
        INC     D               ; Yes, so increment high byte D = D + 1
        JR      L1FB0           ; Continue Diagnostics




;----------------------------------------------------
;       Check Keyboard for "M" Pressed
;      C=1, Pressed       C=0, Not Pressed
;---------------------------------------------------- 
L1FD3:  LD      HL,0BE0Bh       ; Check Keyboard Buffer
        BIT     0,(HL)          ; Has Key been pressed?
        JR      Z,L1FEC         ; No, so skip ahead
        RES     0,(HL)          ; Clear Keyboard Buffer
        LD      A,(0BE0Ah)      ; Get Keyboard Character
        CP      04Dh            ; Was "M" Pressed?
        JR      NZ,L1FEC        ; No, so skip ahead       
        LD      DE,(0C013h)     ; Get Frame Number, "Thayer's Quest" Title
        CALL    L1C57           ; PAUSE on Frame Number
        SCF                     ; C = 1
        RET                     ; Return (1)
L1FEC:  XOR     A               ; C = 0 
        RET                     ; Return (0)






;----------------------------------------------------
;              Diagnostics MENU MODE
;---------------------------------------------------- 
;           "A" = RAM Test
;           "B" = EPROM Test
;           "C" = Display Test
;           "D" = Keyboard Test
;           "E" = Communications Link Test
;           "F" = Monitor Test
;           "G" = Restart Dianostics from beginning
;---------------------------------------------------- 
L1FEE:  CALL    L2180           ; Reset Scoreboard to zero
        LD      DE,000A4h       ; Phrase="Menu Mode Press Key A Through G To Choose A Test" 
        CALL    L1363           ; Call Speech Routine (phrase)           
        LD      E,000h          ; DE = 0000h
        LD      D,000h          ; DE = 0000h
        LD      HL,0BE0Bh       ; Check Keyboard Buffer
L1FFE:  BIT     0,(HL)          ; Has a key been pressed?
        JR      Z,L1FFE         ; No key pressed so just loop
        RES     0,(HL)          ; Clear keypress buffer
        LD      A,(0BE0Ah)      ; Get Keyboard Character
        SUB     041h            ; Subtract 65d
        JR      C,L200F         ; Key < "A" then Invalid Key
        CP      007h            ; Check for Key > "G"
        JR      C,L2017         ; No, so it is a Valid Key
;----------------------------------------------------
;             Invalid Key Pressed
;---------------------------------------------------- 
L200F:  LD      DE,0003Eh       ; Phrase="That Won't Work Here (%)"
        CALL    L1363           ; Call Speech Routine (phrase)           
        JR      L1FEE           ; Continue monitoring keyboard

;----------------------------------------------------
;             Valid Key Pressed
;---------------------------------------------------- 
L2017:  ADD     A,A             ; A = A*2
        LD      B,A             ; B = A
        LD      DE,000A5h       ; Initial phrase="Start of RAM Test"
        ADD     A,E             ; Index to correct phrase
        LD      E,A             ; Store new index to phrase
        JR      NC,L2021        ; Handle carry
        INC     D               ; Carry set, so bump upper byte
L2021:  PUSH    DE              ; Save Phrase Number to stack
        PUSH    DE              ; Save Phrase Number to stack
        CALL    L1363           ; Call Speech Routine (phrase)
        LD      A,B             ;
        LD      DE,01F81h       ;
        ADD     A,E             ;
        LD      E,A             ;
        JR      NC,L202F        ;
        INC     D
L202F:  LD      A,(DE)
        LD      L,A
        INC     DE
        LD      A,(DE)
        LD      H,A
        LD      DE,02039h       ; DE = Return Address 
        PUSH    DE              ; Save DE Register
        JP      (HL)            ; Jump to Test Routine
L2039:  POP     DE              ; Restore DE Register
        POP     DE              ; Restore DE Register
        INC     DE              ; Increment ?
        CALL    L1363           ; Call Speech Routine (phrase) 
        JR      L1FEE           ; Loop on MENU MODE







;----------------------------------------------------
;                  Begin RAM Test
;---------------------------------------------------- 
L2041:  POP     IX              ; IX = Pointer to next test
        POP     IY
        POP     DE
;----------------------------------------------------
;          Fill RAM A000-BFFF with 55h
;---------------------------------------------------- 
        LD      B,055h          ; B = 55h
        DI                      ; Disable Interrupts

L2049:  LD      HL,0A000h       ; Point to start of RAM
L204C:  LD      (HL),B          ; Put 55/AAh into RAM location
        INC     HL              ; Point to next RAM spot
        LD      A,H             ; A = H
        OR      L               ; A = A OR L, check HL = 0000h
        JR      NZ,0204C        ; Loop until end of bank       

        LD      HL,0A000h       ; Point to beginning of RAM
L2055:  LD      A,(HL)          ; Check to see if RAM was written correctly
        CP      B               ; Compare byte with 55/AAh
        JR      NZ,L2067        ; Not correct, show "FAILED" screen           
        INC     HL              ; Point to next RAM location
        LD      A,H             ; A = H
        CP      0C0h            ; Is address C000?
        JR      NZ,L2055        ; No, so loop until C000 is reached

        LD      A,0AAh          ; A = AAh
        CP      B               ; Have we done AA yet?
        JR      Z,L2074         ; Yes, so clear out RAM
        LD      B,A             ; B = AAh
        JR      L2049           ; Fill RAM with AAh





;----------------------------------------------------
;      Display Message, "RAM Test failed"
;---------------------------------------------------- 
L2067:  CALL    L1CA3           ; Check LDPLAYER type by checking the DIPs
        LD      DE,(0C00Bh)     ; Get Frame Number, "RAM Test failed"
        CALL    L1C57           ; PAUSE on Frame Number
        JP      L218B           ; Wait for Diagnostic DIP to be switched OFF




;----------------------------------------------------
;             Clear RAM A000-FFFF 
;---------------------------------------------------- 
L2074:  LD      HL,0A000h       ; HL = A000, first location of RAM
L2077:  LD      (HL),000        ; Clear out location
        INC     HL              ; Point to next location
        LD      A,H             ; A = H
        OR      L               ; HL = FFFF?
        JR      NZ,L2077        ; Loop until all spots cleared
;----------------------------------------------------
;         Load pointer to next Test
;---------------------------------------------------- 
        CALL    L1CA3           ; Check LDPLAYER type by checking the DIPs
        LD      SP,0BFFFh       ; Set Stack Pointer to BFFF
        PUSH    DE              ; Save DE Register
        PUSH    IY              ; Save IY Register
        EI                      ; Enable Interrupts
        JP      (IX)            ; Jump to next test
                             ;77


;----------------------------------------------------
;         Perform EPROM Checksum Test
;---------------------------------------------------- 
L2081:  LD      IY,0C006h
        LD      HL,L0000
        CALL    L20C1
        RET     Z

        LD      DE,(0C00Dh)     ; Frame # "ROM Checksum failed, Display indicates bad block"
        CALL    L1C57           ; PAUSE on Frame Number
        LD      C,0F7h
        LD      HL,01F8Fh
        LD      A,L
        ADD     A,B
        LD      L,A
        LD      B,002h
        JR      NC,L20A9               
        INC     H

L20A9:  OTIR   
        JP      L218B
        LD      HL,LC000
        LD      B,001h
        CALL    L20C1
        RET     Z

        LD      DE,(0C00F)      ; Get Frame Number, "Cartridge ROM Checksum Failed"
        CALL    L1C57           ; PAUSE on Frame Number
        JP      L218B

L20C1:  LD      DE,00000h
L20C4:  LD      A,(HL)
        ADD     A,E
        LD      E,A
        JR      NC,L20CA               
        INC     D
L20CA:  INC     HL
        LD      A,L
        CP      000h
        JR      NZ,L20C4               
        LD      A,H
        CP      080h
        JR      NZ,L20C4               
        LD      A,(IY+000h)
        CP      E
        INC     IY
        LD      A,(IY+000h)
        RET     NZ
        CP      D
        RET     





;----------------------------------------------------
;           Begin Scoreboard Test
;----------------------------------------------------
L20E1:  LD      C,000h          ; C = 0
L20E3:  LD      A,C             ; A = C
        LD      B,008h          ; Loop = 8
L20E6:  OUT     (0F6h),A        ; Output to Scoreboard
        OUT     (0F7h),A        ; Output to Scoreboard
        ADD     A,010h          ; Point to next spot
        DEC     B               ; Decrement Loop
        JR      NZ,L20E6        ; Loop until all spots filled     
        LD      HL,0BE0Bh       ; Get Keyboard Buffer
        BIT     0,(HL)          ; Has a key been pressed?
        RES     0,(HL)          ; Clear Keyboard Buffer
        JR      Z,L20FC         ; No key pressed, so skip ahead
        CALL    L2180           ; Reset Scoreboard to zero
        RET                     ; Return from test   
L20FC:  PUSH    BC              ; Save BC Register
        LD      DE,0001Fh       ; Timer = 1Fh
        CALL    L2163           ; Wait until Timer Expires
        POP     BC              ; Restore BC Register
        INC     C               ; C = C + 1, next digit
        LD      A,00Ah          ; A = 10
        CP      C               ; Have we done all digits?
        JR      NZ,L20E3        ; No, so continue loop
        JR      L20E1           ; Restart digits and loop again       






;----------------------------------------------------
;          Blank out Scoreboard
;----------------------------------------------------
L210C:  LD      A,00Fh          ; Get Blank character
        LD      B,008h          ; Loop = 8
L2110:  OUT     (0F6h),A        ; Send character to scoreboard
        OUT     (0F7h),A        ; Send character to scoreboard
        ADD     A,010h          ; Increment position
        DEC     B               ; Decrment Loop
        JR      NZ,L2110        ; Loop until all spots blanked
        RET                     ; Return





;----------------------------------------------------
;          Begin Keyboard Test
;----------------------------------------------------
L211A:  LD      DE,00592h       ; Programmable Timer = 592h
        CALL    L21A7           ; Set Programmable Timer
        LD      HL,0BE0Bh       ; Get Keyboard buffer
L2123:  CALL    L21B3           ; Check if Programmable Timer expired 
        JR      NZ,L2146        ; Timer expired so end test
        BIT     0,(HL)          ; Has a key been pressed?
        JR      Z,L2123         ; No, so just loop
;----------------------------------------------------
;          Key has been pressed
;----------------------------------------------------
        LD      A,(0BE0Ah)      ; Get Keyboard Character
        RES     0,(HL)          ; Clear keypress buffer 
        BIT     7,A             ; Test if Character is Function Key
        JR      Z,L2141         ; No, so jump ahead
        AND     003h            ; AND Key with 3 (0-3)
        ADD     A,001h          ; Add 1 to Key (Function Keys1-4)
        LD      E,A             ; DE = Address of Key Speech
        LD      D,000h          ; Get word (key)
        CALL    L13C6           ; Call Speech Routine (word)
        JR      L2123           ; Continue Test

L2141:  CALL    L19B0           ;
        JR      L2123           ; Continue Test
;----------------------------------------------------
;          2 minute Timer expired, End Test
;----------------------------------------------------
L2146:  CALL    L2180           ; Reset Scoreboard to zero
        RET                     ; End of Test 






;----------------------------------------------------
;       Begin Communications Link Test
;----------------------------------------------------
L214A:  LD      DE,0005Dh       ; Load "M" key
        CALL    L2163           ; Check for "M" keypress
        RET                     ; Return




;----------------------------------------------------
;       Begin Monitor Test
;----------------------------------------------------
L2151:  LD      DE,0005Dh       ; Load "M" key?
        CALL    L2163           ; Check for "M" keypress
        LD      DE,(0C011h)     ; Get Frame Number, Underwater
        CALL    L1C57           ; PAUSE on Frame Number
L215E:  CALL    L216C           ; Check Diagnostic Mode DIP
        JR      L215E           ; Wait until Diagnostic Mode switched off





;----------------------------------------------------
;              Programmable Timer
;         DE = Programmable Timer value
;----------------------------------------------------
L2163:  CALL    L21A7           ; Set Programmable Timer
L2166:  CALL    L21B3           ; Check if Programmable Timer expired
        JR      Z,L2166         ; Loop until Timer expires
        RET                     ; Timer expired, so return




;----------------------------------------------------
;           Check Diagnostic Mode DIP
;----------------------------------------------------
L216C:  IN      A,(0F1h)        ; GetDIP Switch B
        BIT     0,A             ; Test B1, Diagnostic Mode
        JR      Z,L2178         ; Diagnostic Mode set, so skip ahead
        CALL    L2180           ; Reset Scoreboard to zero
        JP      L0000           ; RESET Program 

L2178:  CALL    L1FD3           ; Check Keyboard for "M" pressed
        RET     NC              ; "M" not pressed so return
        POP     HL              ; Restore HL Register
        JP      L1FEE           ; Jump Diagnostics MENU MODE


;----------------------------------------------------
;              Reset Scoreboard to Zero
;----------------------------------------------------
L2180:  XOR     A               ; A = 00h
        LD      (0BE0Dh),A      ; Store 0 in credits 
        LD      (0BE0Eh),A      ; Store 0 in credits
        CALL    L210C           ; Blank out Scoreboard
        RET                     ; Return



;----------------------------------------------------
;     Loop unit Diagnostic Mode DIP switched OFF
;----------------------------------------------------
L218B:  CALL    L216C           ; Check Diagnostic Mode DIP
        JR      L218B           ; Just keep looping       





;----------------------------------------------------
;      Check Keyboard for a valid Keypress
;       A = Character, Z = Set, Z = Clear
;----------------------------------------------------
L2190:  PUSH    BC              ; Save BC Register
        PUSH    DE              ; Save DE Register
        PUSH    HL              ; Save HL Register
        PUSH    IY              ; Save IY Register
        LD      HL,0BE0Bh       ; Check Keyboard Buffer
        BIT     0,(HL)          ; Check for keypress
        SCF                     ; Carry = set, no keypress
        JR      Z,L21A1         ; No keypress, so leave routine
        LD      A,(0BE0Ah)      ; Get Keyboard Character
        OR      A               ; Z = Clear
L21A1:  POP     IY              ; Restore IY Register
        POP     HL              ; Restore HL Register
        POP     DE              ; Restore DE Register
        POP     BC              ; Restore BC Register
        RET                     ; Return




;----------------------------------------------------
;             Start Programmable Timer
;----------------------------------------------------
;     DE = Timer Start Value
;----------------------------------------------------
L21A7:  PUSH    HL              ; Save HL Register
        LD      HL,0BE07h       ; Get Programmable Timer Register
        LD      (HL),001h       ; Start Programmable Timer 
        INC     HL              ; Point to Timer
        LD      (HL),E          ; Load Value into Programmable Timer
        INC     HL              ; Point to Timer
        LD      (HL),D          ; Load Value into Programmable Timer
        POP     HL              ; Restore HL Register
        RET                     ; Return





;----------------------------------------------------
;        Check if Timer expired
;            Z = 0, still running
;            Z = 1, expired
;----------------------------------------------------
L21B3:  PUSH    HL              ; Save HL Register
        LD      HL,0BE07h       ; Check Programmable Timer Register
        BIT     1,(HL)          ; Is Timer still running?
        JR      Z,L21BF         ; Yes, return Z=0, skip ahead     
        RES     1,(HL)          ; Clear Timer
        OR      0FFh            ; return Z=1, Timer expired
L21BF:  POP     HL              ; Restore HL Register
        RET                     ; Return







;----------------------------------------------------
;        Command Speech Chip to speak buffer
;----------------------------------------------------
L21C1:  PUSH    IY              ; Save IY Register
        PUSH    HL              ; Save HL Register
        PUSH    DE              ; Save DE Register
        PUSH    BC              ; Save BC Register
        CALL    L225B           ; Replace string shortcuts in Speech Buffer
        CALL    L230D           ; Remove invalid characters in Speech Buffer
;----------------------------------------------------
;   Make a copy of the Speech Buffer (A000 -> A500)
;----------------------------------------------------
        LD      HL,0A000h       ; Source = A000
        LD      DE,0A500h       ; Destination = A500
        LD      BC,00100h       ; Number of bytes to copy
        LDIR                    ; Copy all bytes
;----------------------------------------------------
; Do Inflection and Character Classification (A100,A200)
;----------------------------------------------------
        LD      A,(0A614h)      ; Get number of characters in Speech buffer
        LD      (0A6D3h),A      ; Save number of characters
        LD      HL,0A000h       ; Get pointer to Speech buffer
        LD      (0A604h),HL     ; Save pointer to Speech buffer
        CALL    L25A2           ; Get Inflection Control Codes (A100) 
        CALL    L267A           ; Classify all characters VOWEL,CONST.,etc. (A200)

;----------------------------------------------------
;    Setup loop in order to perform Phonetic Rules
;----------------------------------------------------
        LD      HL,0A400h       ; HL = Phoneme pointer to A400
        LD      (0A608h),HL     ; Save A400 Phoneme pointer
        SUB     A               ; A = 0
        LD      (0A615h),A      ; Reset number of characters processed     
;----------------------------------------------------
;  Check if all speech characters have rules checked
;----------------------------------------------------
L21F3:  LD      HL,0A615h       ; Point to number of characters processed
        LD      A,(0A614h)      ; Get number of characters in Speech buffer
        LD      C,(HL)          ; Get number of characters processed
        CP      C               ; Have we processed all characters?
        JR      Z,L2238         ; No, process last character
        JR      NC,L2238        ; More characters to process so skip ahead

;----------------------------------------------------
;            Apply voice characteristics
;----------------------------------------------------
        CALL    L26CD           ; Apply voice characteristics

;----------------------------------------------------
;    Prepare Speech Chip for speaking of Phonemes
;----------------------------------------------------
        LD      HL,0A000h       ; Message Pointer = A000h
        LD      (0A60Ah),HL     ; Store pointer of Message
        DI                      ; Disable Interrupts
;----------------------------------------------------
;         Request interrupt from Speech Chip
;----------------------------------------------------         
        LD      A,080h          ; Raise Control bit in Register3
        OUT     (003h),A        ; Send to register3
        LD      A,0C0h          ; Set phoneme to PAUSE
        OUT     (000h),A        ; Send to register0
        LD      A,07Fh          ; Lower Control bit in Register3
        OUT     (003h),A        ; Send to register3
;----------------------------------------------------
;           Send data packet to Speech Chip
;----------------------------------------------------
        LD      HL,(0A60Ah)     ; Buffer Pointer = A000,A100,A200,...
        LD      C,004h          ; Output to Speech Registers 4,3,2,1,0
        LD      B,005h          ; Loop = 5 registers
L221C:  LD      A,(HL)          ; Get init code from buffer
        OUT     (C),A           ; Send value to register
        INC     H               ; Next locatoin (A000,A100,A200,...)
        DEC     C               ; Next register (port)
        DJNZ    L221C           ; Loop until all registers are written
        EI                      ; Enable Interrupts
;----------------------------------------------------
;     Wait here until interrupt routine sends this
;     data packet to the Speech Chip   
;----------------------------------------------------
L2224:  LD      A,(0A60Ah)      ; Get number of characters spoken
        LD      C,A             ; C = Number of characters spoken
        LD      A,(0A608h)      ; Get number of codes in buffer (A400)
        SUB     C               ; Has entire buffer been spoken?
        JR      C,L2232         ; Buffer has been spoken, so skip ahead
        JR      Z,L2232         ; Buffer has been spoken, so skip ahead
        JR      L2224           ; Loop until entire buffer is spoken 
                     
;----------------------------------------------------
;    Speech complete, restore registers and return
;----------------------------------------------------
L2232:  POP     BC              ; Restore BC Register
        POP     DE              ; Restore DE Register
        POP     HL              ; Restore HL Register
        POP     IY              ; Restore IY Register
        RET                     ; Return










;----------------------------------------------------
;     Process Speech buffer before sending it out
;----------------------------------------------------
;      C = Character spot being processed
;----------------------------------------------------
;      Insert A100 Inflection Code into A400
;----------------------------------------------------
L2238:  LD      B,000h          ; BC = Character spot being checked
        LD      HL,0A100h       ; Point to A100 inflection codes
        ADD     HL,BC           ; Index into A100 codes
        LD      A,(HL)          ; Get A100 Inflection Code
        OR      A               ; Is there an inflection code?
        JR      Z,L224A         ; No, so skip ahead
        LD      HL,(0A608h)     ; Get A400 Pointer
        LD      (HL),A          ; Save control code at Control Code Index (A400)
        INC     HL              ; Point to next A400 locaton
        LD      (0A608h),HL     ; Save Control Code Pointer
;----------------------------------------------------
;           Check for Phoneme Rules
;----------------------------------------------------
L224A:  LD      HL,0A000h       ; Point to A000 text
        ADD     HL,BC           ; Index into A000 text
        LD      A,(HL)          ; Get character
        SUB     020h            ; Does character follow Rules (32-96)?
        JP      NC,L2335        ; Yes, so apply Rules 
        LD      HL,0A615h       ; Get number of characters processed
        INC     (HL)            ; Increment number of speech characters processed
        JP      L21F3           ; Loop back until all speech characters processed








;----------------------------------------------------
; Check for string shortcuts (*,$,%,#,n) in Speech Buffer
;----------------------------------------------------
L225B:  LD      A,(0A64Ah)      ; Get Length of Player's Name
        LD      C,A             ; C = Length of Player's Name
        LD      A,(0A614h)      ; Get number of characters in Speech Buffer
        INC     A               ; Add one character
        LD      B,A             ; B = Number of characters + 1
;----------------------------------------------------
;       Check if buffer has enough room for name
;----------------------------------------------------
        ADD     A,C             ; Is there room for Player's Name?
        RET     C               ; Too many characters in buffer, so return

        ADD     A,014h          ; Is there room for a SPACE between words (20 chars)?
        RET     C               ; Too many characters in buffer, so return

;----------------------------------------------------
;    Search buffer for string shortcuts (*,$,%,#,n)
;----------------------------------------------------
        LD      HL,0A000h       ; HL = Start of Speech Buffer
L226C:  LD      A,02Ah          ; Check for Name shortcut (*)
        CP      (HL)            ; Is Name shortcut in Speech Buffer?
        JR      Z,L2289         ; Yes, so speak Name       
        LD      A,024h          ; Check for Name shortcut ($)
        CP      (HL)            ; Is Name shortcut in Speech Buffer?
        JR      Z,L2289         ; Yes, so speak Name         
        LD      A,025h          ; Check for Name shortcut (%)
        CP      (HL)            ; Is Name shortcut in Speech Buffer?
        JR      Z,L2289         ; Yes, so speak Name         
        LD      A,023h          ; Check for Name shortcut (#)
        CP      (HL)            ; Is Name shortcut in Speech Buffer?
        JR      Z,L2289         ; Yes, so speak Name               
        LD      A,06Eh          ; Check for Name shortcut (n)
        CP      (HL)            ; Is Name shortcut in Speech Buffer?
        JR      Z,L2289         ; Yes, so speak Name               
        INC     HL              ; Check next buffer character
        DJNZ    L226C           ; Loop until whole buffer is checked       
        RET                     ; Name shortcuts not found so return

;----------------------------------------------------
;           Replace shortcut with String 
;----------------------------------------------------
;      Save first part of Speech Buffer temporarily
;----------------------------------------------------
L2289:  LD      C,L             ; BC = Spot where name occurs in buffer
        LD      B,000h          ; Copy up until occurance
        LD      HL,0A000h       ; Source = A000
        LD      DE,0A400h       ; Destination = A400
        LDIR                    ; Copy all bytes
;----------------------------------------------------
;      Insert replacement string into temp buffer
;----------------------------------------------------
        LD      A,(0A614h)      ; A = Number of characters in Speech Buffer
        SUB     L               ; Subtract where name occurs in buffer
        LD      C,A             ; BC = Number of characters after name
        INC     HL              ; Source HL = Start of remaining characters
        PUSH    HL              ; Save copy source
        PUSH    BC              ; Save copy number of characters
        CALL    L22B7           ; Setup string to replace shortcut with
        JR      C,L22A3         ; Do not copy string, just skip ahead       
        LDIR                    ; Copy Replacement String into buffer
;----------------------------------------------------
;      Save last part of Speech Buffer temporarily
;----------------------------------------------------
L22A3:  POP     BC              ; Restore number of characters to copy
        POP     HL              ; Restore source to copy from
        LDIR                    ; Restore characters after occurance
;----------------------------------------------------
;            Restore whole Speech Buffer
;----------------------------------------------------
        LD      C,E             ; BC = Total number of characters to copy back
        LD      HL,0A400h       ; Source = A400
        LD      DE,0A000h       ; Destination = A000
        LDIR                    ; Copy all bytes back
        LD      A,E             ; A = number of characters in buffer
        DEC     A               ; Subtract 1 character
        LD      (0A614h),A      ; Save new Speech Buffer size
        JR      L225B           ; Continue to check Speech Buffer       





;----------------------------------------------------
;         Check what to replace shortcut with
;----------------------------------------------------
;          (#) = Player's Full Name
;          (*) = Player's First Name
;          ($) = First Name -or- Full Name
;          (%) = First Name -or- nothing
;          (n) = Score
;----------------------------------------------------
L22B7:  DEC     HL              ; Point to shortcut
        LD      A,(HL)          ; Get shortcut character
        CP      023h            ; Is it Player's Full Name (#)?
        JR      Z,L22E8         ; Yes, so replace shortcut with Player's full name       
        CP      024h            ; Is it Player's First name/Full name ($)?
        JR      Z,L22D2         ; Yes, so replace shortcut with Player's First name/Full name       
        CP      06Eh            ; Is it Score (n)?
        JR      Z,L22F5         ; Yes, so replace shortcut with Score
        CP      02Ah            ; Is it Player's first name (*)?
        SCF                     ; Set flag for just the first name
        JR      Z,L22D2         ; Yes, so replace shortcut with Player's first name
        LD      A,R             ; (%) First name or nothing, so get Random Number
        AND     008h            ; Check heads or tails
        JR      Z,L22D2         ; Tails so speak first name     
        SCF                     ; Speak nothing, disable string copy
        RET                     ; Return and continue copying characters

;----------------------------------------------------
; Replace shortcut with Player's First name or Full name
;----------------------------------------------------
L22D2:  LD      HL,0A68Bh       ; Point to length of Player's first name
        LD      A,(HL)          ; Get length of Player's first name
        LD      C,A             ; C = number of characters in first name
        LD      B,000h          ; BC = number of characters in first name
        INC     HL              ; HL = Pointer to Player's first name
        JR      NC,L22DF        ; Do First name or Full name ($)
        OR      A               ; Check length of first name
        JR      NZ,L22F3        ; First name length fine so continue with copy       
;----------------------------------------------------
;  Randomly choose to use the First name or Full name         
;----------------------------------------------------
L22DF:  OR      A               ; Check length of first name
        JR      Z,L22E8         ; First name missing so must use full name                       
        LD      A,R             ; Get random number
        AND     010h            ; Check heads or tails
        JR      Z,L22F3         ; If heads, then skip ahead and speak first name
;----------------------------------------------------
;      Replace shortcut with Player's Full name         
;----------------------------------------------------                       
L22E8:  LD      HL,0A64Ah       ; Get Length of Player's Full Name
        LD      A,(HL)          ; Get length of name 
        LD      C,A             ; BC = length of name
        INC     HL              ; HL = Pointer to Player's Name
        OR      A               ; Check if player name length is zero
        JR      NZ,L22F3        ; Name is not zero so do copy
;----------------------------------------------------
;            Return but don't copy string       
;----------------------------------------------------             
        SCF                     ; Disable string copy
        RET                     ; Return 
;----------------------------------------------------
;              Return and copy string       
;----------------------------------------------------
L22F3:  OR      A               ; Enable string copy
        RET                     ; Return 




;----------------------------------------------------
;           Replace shortcut with Score
;----------------------------------------------------
L22F5:  LD      (0A641h),DE     ; Save end of Speech Buffer
        LD      A,E             ; A = Number of characters pointing to
        DEC     A               ; Subtract shortcut character
        LD      (0A614h),A      ; Store new number of characters in buffer
        LD      HL,0A6D0h       ; HL = Speakable Number (n)
        PUSH    DE              ; Save Speech Buffer Pointer
        CALL    L146F           ; Copy Score (n)
        POP     DE              ; Restore Speech Buffer Pointer
        RET     C               ; Return if buffer overflow
        LD      DE,(0A641h)     ; Add characters to speech buffer
        SCF                     ; Disable copy because it's been done
        RET                     ; Return and continue buffer copy







;----------------------------------------------------
;      Remove invalid characters in Speech Buffer
;----------------------------------------------------
;       Valid ranges:  "0"-"9" 30h-3Ah
;                      "A"-"Z" 41h-5Bh
;----------------------------------------------------
L230D:  LD      HL,(0A614h)     ; L = Number of characters in Speech Buffer
        LD      H,0A0h          ; HL = Pointer to the end of Speech Buffer
        LD      E,(HL)          ; E = last character in buffer (EOB)
L2313:  DEC     L               ; Check next character
        RET     Z               ; All characters checked so return
        LD      A,(HL)          ; Get character from buffer
        CP      030h            ; Is character > (0)?
        JR      C,L2313         ; No, continue checking buffer     
        CP      03Ah            ; Is character < (9+)?
        JR      C,L2326         ; Yes, so delete previous invalid character     
        CP      041h            ; Is character > (A)?
        JR      C,L2313         ; No, so continue checking buffer     
        CP      05Bh            ; Is character < (Z+)?
        JR      NC,L2313        ; No, so continue checking buffer
;----------------------------------------------------
; Delete all characters up to the first valid character
;----------------------------------------------------               
L2326:  LD      A,(0A614h)      ; A = Number of Characters in buffer
        SUB     L               ; Subtract valid character location
        DEC     A               ; Then subtract 1
        RET     Z               ; Return if there was one trailing invalid character
        RET     C               ; Return if there are no trailing invalid characters
        INC     L               ; Point to character after last valid character
        LD      (HL),E          ; Restore final buffer character (EOB)
        LD      A,L             ; Get length of buffer
        INC     A               ; Add the last character
        LD      (0A614h),A      ; Save new number of characters in buffer
        RET                     ; Return








;----------------------------------------------------
;              Apply Rules to Speech
;----------------------------------------------------
;   Find corresponding Rule in Rule Table, and 
;   then put the corresponding codes into A400 for
;   output to the speech chip.
;
;   example:  DISK matches
;            (DIS)=25h,07h,30h  (K)=29h,ADh,C0h
;----------------------------------------------------
;       A = A000 Letter (1-64 subtracted 32)
;----------------------------------------------------
L2335:  ADD     A,A             ; A = 2 * Number 
        LD      C,A             ; Put number into BC
        LD      B,000h          ; BC = Phoneme number
        LD      HL,029F2h       ; Start of Phoneme Table
        ADD     HL,BC           ; Index to correct Phoneme Bank
;----------------------------------------------------
;           Setup Rules Table pointers
;     A612-A613   Start of entry
;     A606        Start of equation
;     A640        Length of entry
;     A616        ?
;     A61E        ?
;----------------------------------------------------
        LD      C,(HL)          ; Get Rule Table index 
        INC     HL              ; Next byte
        LD      B,(HL)          ; Get Rule Table index
        LD      (0A612h),BC     ; Save Rule Table starting location

        INC     BC              ; Start of Phonetic Rule
        LD      (0A606h),BC     ; Save Phonetic Rule start
        LD      HL,(0A612h)     ; Point to rule length
        LD      A,(HL)          ; Get rule length
        LD      (0A640h),A      ; Save length of first Rule
        SUB     A               ; A = 0
        LD      (0A616h),A      ; Clear number of characters to the left
        LD      (0A61Eh),A      ; Clear A61E

;----------------------------------------------------
;           Reset to check Phonetic Rule
;----------------------------------------------------
L2357:  LD      A,(0A615h)      ; Get current speech characters being processed
        LD      (0A617h),A      ; Save this pointer so we can access A200 codes
        LD      A,001h          ; A = +1
        LD      (0A618h),A      ; Initially set Marker
        LD      (0A61Dh),A      ; Set X_Adder = +1
        DEC     A               ; A = 0
        LD      (0A61Ah),A      ; Clear Left Parenthesis
        LD      (0A619h),A      ; Clear Right Parenthesis
        LD      (0A61Bh),A      ; Clear (character) count
        DEC     A               ; A = -1
        LD      (0A61Ch),A      ; Set Z_Adder to -1
        CALL    L254E           ; Skip to next Phoneme Entry 

;----------------------------------------------------
;             Process the Phonetic Rule
;----------------------------------------------------
L2376:  LD      A,(0A616h)      ; Get Rule index
        LD      C,A             ; BC = Rule index
        LD      B,000h          ; BC = Rule index
        LD      HL,(0A606h)     ; Get Phonetic Rule pointer
        ADD     HL,BC           ; Add index to next character
        LD      A,(HL)          ; Get character
;----------------------------------------------------
;        Check rule for control symbols !+#. :=()
;----------------------------------------------------
        CP      021h            ; Character = "!"?
        JR      Z,L23A8         ; Yes, jump ahead
        CP      02Bh            ; Character = "+"?
        JR      Z,L23AB         ; Yes, jump ahead 
        CP      023h            ; Character = "#"?
        JR      Z,L23AE         ; Yes, jump ahead
        CP      02Eh            ; Character = "."?
        JR      Z,L23B1         ; Yes, jump ahead
        CP      05Eh            ; Character = " "?
        JR      Z,L23B4         ; Yes, jump ahead
        CP      03Ah            ; Character = ":"?
        JR      Z,L23B7         ; Yes, jump ahead
        CP      03Dh            ; Character = "="?
        JR      Z,L23BA         ; Yes, jump ahead
        CP      028h            ; Character = "("?
        JR      Z,L23BD         ; Yes, jump ahead
        CP      029h            ; Character = ")"?
        JR      Z,L23C0         ; Yes, jump ahead
        JP      L24D5           ; Any other characters

;----------------------------------------------------
;       Jump ahead depending on the symbol 
;----------------------------------------------------
L23A8:  JP      L23C3           ; "!"
L23AB:  JP      L23D1           ; "+"
L23AE:  JP      L23DF           ; "#"
L23B1:  JP      L2417           ; "."
L23B4:  JP      L2425           ; " "
L23B7:  JP      L2437           ; ":"
L23BA:  JP      L2466           ; "="
L23BD:  JP      L24B5           ; "("
L23C0:  JP      L24C9           ; ")"


;----------------------------------------------------
;       Control Symbol "!"   (non-alphabetic)
;----------------------------------------------------
L23C3:  CALL    L2583           ; Get Character classification symbol (A200)
        CP      021h            ; Check for non-alphabetic character
        JR      Z,L23CE         ; Yes, symbol match
        SUB     A               ; A = 0
        LD      (0A618h),A      ; Clear Marker
L23CE:  JP      L24F4           ; Do Phonetic Rule match check


;----------------------------------------------------
;       Control Symbol "+"   (Vowel EIY only)
;----------------------------------------------------
L23D1:  CALL    L2583           ; Get Character classification symbol (A200)
        CP      02Bh            ; Check for vowel "+" (E,I,Y)
        JR      Z,L23DC         ; Yes, symbol match
        SUB     A               ; A = 0
        LD      (0A618h),A      ; Clear Marker
L23DC:  JP      L24F4           ; Do Phonetic Rule match check


;----------------------------------------------------
;        Control Symbol "#"   (Any Vowel)
;----------------------------------------------------
L23DF:  SUB     A               ; A = 0
        LD      (0A618h),A      ; Clear Match Check
L23E3:  CALL    L2583           ; Get Character classification symbol (A200)
        CP      023h            ; Check for a vowel "#" (Vowel)
        JR      Z,L23FF         ; Yes, symbol match       
        CP      02Bh            ; Check for vowel "+" (E,I,Y)
        JR      Z,L23FF         ; Yes, symbol match
        LD      A,(0A617h)      ;
        OR      A               ;
        JR      Z,L23FC         ;       
        LD      B,A             ;
        LD      A,(0A61Dh)      ; Get X_Adder direction (+1 or -1)
        ADD     A,B             ;
        LD      (0A617h),A      ;
L23FC:  JP      L24F4           ; Do Phonetic Rule match check


;----------------------------------------------------
;         Vowel was found, so set marker
;----------------------------------------------------
L23FF:  LD      A,001h          ; A = 1
        LD      (0A618h),A      ; Set Match Check
        LD      A,(0A617h)      ;
        OR      A               ;
        JR      Z,L23FC         ;       
        LD      B,A             ;
        LD      A,(0A61Ch)      ; Get Z_Adder direction (+1 or -1)
        ADD     A,B             ; Add/subtract 1
        LD      (0A617h),A      ;
        OR      A               ;
        JR      NZ,L23E3        ; No, recheck A200 codes       
        JR      Z,L23FC         ;       


;----------------------------------------------------
;       Handle phoneme equation characters  "."
;----------------------------------------------------
L2417:  CALL    L2583           ; Get Character classification symbol (A200)
        CP      02Eh            ; Is A200 code = "."?
        JR      Z,L2422                 
        SUB     A               ; A = 0
        LD      (0A618h),A      ; Clear Marker
L2422:  JP      L24F4           ; Do Phonetic Rule match check


;----------------------------------------------------
;       Handle phoneme equation characters  " "
;----------------------------------------------------
L2425:  CALL    L2583           ; Get Character classification symbol (A200)
        CP      05Eh
        JR      Z,L2434                 
        CP      02Eh
        JR      Z,L2434                 
        SUB     A               ; A = 0
        LD      (0A618h),A      ; Clear Marker
L2434:  JP      L24F4           ; Do Phonetic Rule match check


;----------------------------------------------------
;       Handle phoneme equation characters  ":"
;----------------------------------------------------
L2437:  CALL    L2583           ; Get Character classification symbol (A200)
        CP      05Eh
        JR      Z,L2453                 
        CP      02Eh
        JR      Z,L2453                 
        LD      A,(0A617h)
        OR      A
        JR      Z,L2450                 
        LD      B,A
        LD      A,(0A61Dh)      ; Get X_Adder direction (+1 or -1)
        ADD     A,B             ; Add/subtract 1
        LD      (0A617h),A      ;
L2450:  JP      L24F4           ; Do Phonetic Rule match check
L2453:  LD      A,(0A617h)
        OR      A
        JR      Z,L2450                 
        LD      B,A
        LD      A,(0A61Ch)      ; Get Z_Adder direction (+1 or -1)
        ADD     A,B             ; Add/subtract 1
        LD      (0A617h),A
        OR      A
        JR      NZ,L2437               
        JR      Z,L2450                 



;----------------------------------------------------
;       Handle phoneme equation characters  "="
;----------------------------------------------------
;   If we match all the way up to the equals sign
;   then we have a complete match, now substitute
;   the phoneme codes for the matching text.
;----------------------------------------------------
L2466:  LD      A,(0A61Ah)
        OR      A
        JR      NZ,L2470               
        LD      HL,0A61Bh       ; Number of characters in parenthesis
        INC     (HL)            ; Increment character count
L2470:  LD      A,(0A61Bh)      ; Get number of characters in parenthesis
        LD      B,A             ; B = Number of characters in parenthesis
        LD      A,(0A615h)
        ADD     A,B
        LD      (0A615h),A
;----------------------------------------------------
;           Replace text with phoneme codes 
;----------------------------------------------------
L247B:  LD      A,(0A616h)      ; Get phoneme character number
        INC     A               ; Point to next character
        LD      (0A616h),A      ; Save phoneme character number
        OR      A
        JR      NZ,L2489               
        LD      HL,0A607h
        INC     (HL)
;----------------------------------------------------
;              Copy codes to A400 
;----------------------------------------------------
L2489:  LD      A,(0A616h)      ; Get phoneme character number
        LD      C,A             ;
        LD      B,000h          ;
        LD      HL,(0A606h)     ; Get start of phoneme codes
        ADD     HL,BC           ; Index to spot after equals sign
        PUSH    HL              ; Save start of phoneme replacement codes
        POP     DE              ; DE = start of phoneme replacement codes
        PUSH    DE              ; Save start of phoneme replacement codes
        LD      HL,(0A612h)     ; Get pointer to Phoneme Bank
        LD      A,(0A640h)      ; Get length of first Entry
        LD      C,A             ; Prepare to skip entry
        ADD     HL,BC           ; Set index to skip to next Phoneme Entry in Bank
        EX      DE,HL
        AND     A               ;
        SBC     HL,DE           ; Have we copied all phoneme codes?
        JR      NC,L24B1        ; All codes copied, leave phoneme routine       
        POP     HL              ;
        LD      A,(HL)          ; Get phoneme replacement code
        LD      HL,(0A608h)     ; Get A400 pointer
        LD      (HL),A          ; Save replacement code 
        INC     HL              ; Point to next location
        LD      (0A608h),HL     ; Save A400 pointer
        JP      L247B           ; Get next phoneme replacement code

L24B1:  POP     HL              ;
        JP      L21F3           ; Loop back until all speech characters processed


;----------------------------------------------------
;          Handle Characters  "("
;----------------------------------------------------
L24B5:  LD      A,001h          ; Set Flag
        LD      (0A61Ah),A      ; Mark Left Parenthesis Mode
        LD      (0A61Ch),A      ; Z_Adder = +1
        DEC     A               ; A =  0
        DEC     A               ; A = -1
        LD      (0A61Dh),A      ; X_Adder = -1
        LD      HL,0A616h       ; Character Pointer in phoneme equation
        INC     (HL)            ; Point to next character in phoneme equation
        JP      L2376           ; Check next phoneme character


;----------------------------------------------------
;             Handle Characters  ")"
;----------------------------------------------------
L24C9:  LD      A,001h          ; Set Flag
        LD      (0A619h),A      ; Mark Right Parenthesis 
        LD      HL,0A616h       ; Character Pointer in Phoneme equation
        INC     (HL)            ; Point to next character in phoneme equation
        JP      L2376           ; Check next phoneme character



;----------------------------------------------------
;         Handle all other characters
;    Check if phoneme equation matches letter code
;----------------------------------------------------
L24D5:  CALL    L2583           ; Get A200 Code for current character
        LD      A,(0A617h)      ; Get current speech buffer pointer
        LD      C,A             ; C = index
        LD      B,000h          ; BC = index
        LD      HL,(0A604h)     ;
        ADD     HL,BC           ;
        LD      A,(HL)          ;
        LD      D,A             ; Check A000 character
        LD      A,(0A616h)      ;
        LD      C,A             ;
        LD      HL,(0A606h)     ; Get Phoneme Equation pointer
        ADD     HL,BC           ;
        LD      A,(HL)          ; Get phoneme character from table
        CP      D               ; Do phoneme characters match text characters?
        JR      Z,L24F4         ; Yes, match found skip ahead
        SUB     A               ; A = 0
        LD      (0A618h),A      ; Clear Match Check

;----------------------------------------------------
;            Phonetic Rule match check
;----------------------------------------------------
L24F4:  LD      A,(0A618h)      ; Get Match Check
        OR      A               ; Was there a match?
        JR      Z,L2534         ; No match found, skip to next Rule   
;----------------------------------------------------
;            Phonetic Rule match found
;----------------------------------------------------
        LD      A,(0A616h)      ; Number of characters to match
        OR      A               ; Have you matched any characters?
        JR      NZ,L2519        ; Yes, keep checking


;----------------------------------------------------
;                     NO MATCH
;----------------------------------------------------                       
;                  Reset Pointers
;----------------------------------------------------
        LD      A,(0A61Eh)      ; Get previous start of Phonetic Rule
        LD      (0A616h),A      ; Reset rule character number
        LD      A,(0A615h)      ; Get previous speech buffer pointer
        LD      (0A617h),A      ; Reset speech buffer pointer
;----------------------------------------------------
;               Reset directionals
;----------------------------------------------------
        LD      A,001h          ; A = 1
        LD      (0A61Ch),A      ; Z_Adder = +1
        DEC     A               ; A = 0
        DEC     A               ; A = -1
        LD      (0A61Dh),A      ; X_Adder = -1
        JP      L2531           ; Loop back





;----------------------------------------------------
;               A = phoneme characters to skip
;----------------------------------------------------
L2519:  LD      C,A
        LD      B,000h
        LD      A,(0A61Ch)      ; Get Z_Adder direction (+1 or -1) 
        ADD     A,C             ; Increment/decrement number of characters that matched
        LD      (0A616h),A
        LD      A,(0A617h)
        OR      A
        JR      Z,L2531                 
        LD      C,A
        LD      A,(0A61Ch)      ; Get Z_Adder direction (+1 or -1)
        ADD     A,C
        LD      (0A617h),A
;----------------------------------------------------
;     
;----------------------------------------------------
L2531:  JP      L2376           ; Check next phoneme character

;----------------------------------------------------
;     No match found skip to next phoneme entry
;----------------------------------------------------
L2534:  LD      HL,(0A612h)     ; Get phoneme entry start
        LD      A,(HL)          ; Get length of entry
        LD      E,A             ; DE = number of characters to skip
        LD      D,000h          ; Setup to skip DE characters
        ADD     HL,DE           ; Skip to next entry
        LD      (0A612h),HL     ; Save new entry location
        LD      A,(HL)          ; Get length of phoneme entry
        LD      (0A640h),A      ; Save length of entry
        INC     HL              ; Point to start of phoneme entry
        LD      (0A606h),HL     ; Save start pointer
        SUB     A               ; A = 0
        LD      (0A616h),A      ; Reset back to first phoneme character
        JP      L2357           ; Skip to next Phoneme entry





;----------------------------------------------------
;         Skip to the next/prev Phoneme Entry
;----------------------------------------------------
;      Skip all characters up until "=" or "("
;----------------------------------------------------
L254E:  LD      HL,(0A606h)     ; Get Phoneme Equation pointer
        LD      E,000h          ; Set counter to zero

L2553:  LD      A,(HL)          ; Get Phoneme equation character
        CP      028h            ; Have we found a new entry"("?
        JR      Z,L2562         ; Yes, so stop counting
        CP      03Dh            ; Is it equals sign "="?
        JR      Z,L2562         ; Yes, so stop counting       
        INC     E               ; Increment characters skipped
        INC     HL              ; Point to next character
        LD      A,E             ; Check character count
        OR      A               ; More than 255 characters?
        JR      NZ,L2553        ; No, so keep counting       
;----------------------------------------------------
;        Next Phoneme entry found, update index
;----------------------------------------------------
L2562:  LD      A,E             ; Get number characters skipped
        LD      (0A616h),A      ; Update number of characters
        LD      (0A61Eh),A      ; Save copy of number of characters
        OR      A               ; Are there any characters?
        JR      Z,L2582         ; No characters so just return
;----------------------------------------------------
;          Check number of entries scanned
;----------------------------------------------------               
        LD      C,A             ; C = number of characters
        LD      A,(0A61Ch)      ; Get Z_Adder direction (+1 or -1)
        ADD     A,C             ; Add/subtract 1
        LD      (0A616h),A      ; Save start of new entry
        LD      A,(0A617h)      ; Get character total
        OR      A               ; Are there any characters?
        JR      Z,L2582         ; No, so just return
        LD      C,A             ; C = total characters
        LD      A,(0A61Ch)      ; Get Z_Adder direction (+1 or -1)
        ADD     A,C             ; Add/subtract 1
        LD      (0A617h),A      ; Save total
L2582:  RET                     ; Return






;----------------------------------------------------
;     Get Character classification symbol (A200)
;----------------------------------------------------
;     Return A = Classification Symbol (!#+? .)
;----------------------------------------------------
L2583:  LD      A,(0A61Ah)      ; Check for left Parenthesis
        OR      A               ; Are we in left parenthesis?
        JR      Z,L2596         ; No, so skip ahead
        LD      A,(0A619h)      ; Check for right parenthesis 
        OR      A               ; Have we closed right parenthesis?
        JR      NZ,L2596        ; Yes, so skip ahead
;----------------------------------------------------
;   Count number of characters inside parenthesis
;----------------------------------------------------
        LD      A,(0A61Bh)      ; Get (character) count
        INC     A               ; Increment count
        LD      (0A61Bh),A      ; Save (character) count
;----------------------------------------------------
;           Get A200 Classification Symbol
;----------------------------------------------------
L2596:  LD      A,(0A617h)      ; Get current speech buffer pointer
        LD      C,A             ; C = index
        LD      B,000h          ; BC = index
        LD      HL,0A200h       ; Point to A200 table
        ADD     HL,BC           ; Index into A200 table
        LD      A,(HL)          ; Get A200 code
        RET                     ; Return






;----------------------------------------------------
;          Process Speech for Inflection 
;----------------------------------------------------
;  (A6D3)       Number of characters in Speech Buffer
;  (A604-A605)  Pointer to start of Speech Buffer A000
;----------------------------------------------------
;  Insert Voice Control Codes (A100) based on
;  sentence inflection and punctuation.
;         CHAR          CODE
;         -------       ----
;         "!"           F9h, 1001, 1
;         ",;:"         FAh, 1010, 2
;         ".?"          FBh, 1011, 3
;         "/"           FCh, 1100, 4
;                       FFh  1111, OFF
;----------------------------------------------------
L25A2:  SUB     A               ; A = 0
        LD      BC,00000h       ; Clear counter
        LD      (0A620h),A      ; Clear Backslash Flag
        LD      (0A621h),A      ; Clear Question Flag
        LD      HL,(0A604h)     ; Pointer to Speech Buffer
L25AF:  LD      E,(HL)          ; E = Character from Speech Buffer
        LD      A,(0A621h)      ; Get Question Flag
        OR      A               ; Are we asking a question already?
        JR      Z,L25BA         ; No, so check for "WH" occurance       
        LD      A,E             ; Get character
        JP      L25CF           ; Skip ahead and check for punctuation
;----------------------------------------------------
;        Check if questions starts with "WH"       
;     ie. WHere, WHen, WHat, WHo 
;----------------------------------------------------
L25BA:  LD      A,E             ; A = Character
        CP      057h            ; Character = "W"?
        JR      NZ,L25CF        ; No, so check for inflection         
        INC     HL              ; Point to next character
        LD      A,(HL)          ; Get next character
        CP      048h            ; Character = "H"?
        JR      NZ,L25CC        ; No, so skip ahead
        LD      A,(0A621h)      ; Get Question Flag
        INC     A               ; Increment Question Flag
        LD      (0A621h),A      ; Save Question Flag
L25CC:  LD      A,057h          ; Character = "W"
        DEC     HL              ; Point back to first character
;----------------------------------------------------
;          Check for inflection identifiers         
;----------------------------------------------------
L25CF:  PUSH    HL              ; Save character pointer
        CP      021h            ; Is character = "!"?
        JR      Z,L25F5         ; Yes, so jump ahead     
        CP      02Ch            ; Is character = ","?
        JR      Z,L2603         ; Yes, so jump ahead       
        CP      02Eh            ; Is character = "."?
        JR      Z,L2611         ; Yes, so jump ahead
        CP      02Fh            ; Is character = "/"?
        JR      Z,L263D         ; Yes, so jump ahead
        CP      03Ah            ; Is character = ":"?
        JR      Z,L2603         ; Yes, so jump ahead       
        CP      03Bh            ; Is character = ";"?
        JR      Z,L2603         ; Yes, so jump ahead
        CP      03Fh            ; Is character = "?"?
        JR      Z,L261F         ; Yes, so jump ahead

;----------------------------------------------------
;             Not an inflection character 
;----------------------------------------------------
        LD      E,A             ; Save normal character
        SUB     A               ; A = 0
        LD      (0A61Fh),A      ; No Control Code
        LD      A,E             ; Restore character
        JP      L264D           ; Write inflection control code


;----------------------------------------------------
;              Handle Character  "!"     
;----------------------------------------------------
L25F5:  LD      E,A             ; Save character
        LD      A,0F9h          ; A = Inflection Level 1 
        LD      (0A61Fh),A      ; Store Speech Control Code
        SUB     A               ; A = 0
        LD      (0A620h),A      ; Clear Backslash Flag
        LD      A,E             ; Restore character
        JP      L264D           ; Write inflection control code


;----------------------------------------------------
;             Handle Characters  ",;:"
;----------------------------------------------------
L2603:  LD      E,A             ; Save character
        LD      A,0FAh          ; A = Inflection Level 2
        LD      (0A61Fh),A      ; Store Speech Control Code
        SUB     A               ; A = 0
        LD      (0A620h),A      ; Clear Backslash Flag
        LD      A,E             ; Restore character
        JP      L264D           ; Write inflection control code


;----------------------------------------------------
;       Handle Character  "."
;----------------------------------------------------
L2611:  LD      E,A             ; Save character
        LD      A,0FBh          ; A = Inflection Level 3
        LD      (0A61Fh),A      ; Store Speech Control Code
        SUB     A               ; A = 0
        LD      (0A620h),A      ; Clear Backslash Flag
        LD      A,E             ; Restore character
        JP      L264D           ; Write inflection control code


;----------------------------------------------------
;             Handle Character  "?"
;----------------------------------------------------
L261F:  LD      E,A             ; Save character
        LD      A,(0A621h)      ; Get Question Flag
        OR      A               ; Is a questions being asked?
        JR      Z,L262D         ; No, so skip ahead
        LD      E,02Eh          ; Change "?" to a "."
        LD      A,0FBh          ; A = Inflection Level 3
        JP      L262F           ; Skip ahead
L262D:  LD      A,0FFh          ; A = Inflection Level Off
L262F:  LD      (0A61Fh),A      ; Store Speech Control Code
        SUB     A               ; A = 0
        LD      (0A620h),A      ; Clear Backslash Flag
        LD      (0A621h),A      ; Clear Question Flag
        LD      A,E             ; Restore character
        JP      L264D           ; Write inflection control code


;----------------------------------------------------
;       Handle Character  "/" inflection
;----------------------------------------------------
L263D:  LD      A,0FCh          ; A = Inflection Level 4
        LD      HL,0A100h       ; Point to A100 Voice Control codes
        ADD     HL,BC           ; Index into buffer
        LD      (HL),A          ; Save Voice Control Code
        DEC     BC              ; Erase the backslash character
        LD      A,001h          ; Note that backslash has been erased
        LD      (0A620h),A      ; Set Backslash Flag
        JP      L2667           ; Continue checking buffer



;----------------------------------------------------
;       Write Inflection Control Code into A000
;----------------------------------------------------
L264D:  LD      HL,0A000h       ; Point to speech buffer
        ADD     HL,BC           ; Index into buffer 
        LD      (HL),A          ; Save character
;----------------------------------------------------
;     Skip A100 code if there was a backslash (/)
;----------------------------------------------------
        LD      A,(0A620h)      ; Get Backslash Flag
        OR      A               ; Was there a backslash (/)?
        JR      Z,L265F         ; No, so record Voice Control Code
        SUB     A               ; A = 0
        LD      (0A620h),A      ; Clear Backslash Flag
        JP      L2667           ; Continue checking buffer
;----------------------------------------------------
;         Store Voice Control Code at A100
;----------------------------------------------------
L265F:  LD      A,(0A61Fh)      ; Get Speech Control Code
        LD      HL,0A100h       ; Point to A100 control codes
        ADD     HL,BC           ; Index into buffer
        LD      (HL),A          ; Save Speech Control Code
;----------------------------------------------------
;    Increment loop to check all speech characters
;----------------------------------------------------
L2667:  INC     BC              ; Increment loop counter
        POP     HL              ; Restore character pointer
        INC     HL              ; Point to next character
        LD      A,(0A614h)      ; Get length of buffer
        CP      L               ; Are we at the end of the buffer?
        JP      NC,L25AF        ; No, so loop back
        JP      Z,L25AF         ; No, so loop back
;----------------------------------------------------
;           Finished checking speech buffer
;----------------------------------------------------
        DEC     BC              ; Decrement loop counter
        LD      A,C             ; Get number of character
        LD      (0A614h),A      ; Save number of characters in speech buffer
        RET                     ; Return







;----------------------------------------------------
;  Get Classification Symbol for all characters (A200)
;----------------------------------------------------
;  (A604-A605)  Pointer to start of Speech Buffer
;----------------------------------------------------
L267A:  LD      A,(0A614h)      ; Get number of characters in Speech Buffer
        LD      E,A             ; E = number of characters in buffer
        LD      D,000h          ; DE = number of characters in buffer
        LD      C,A             ; BC = number of characters in buffer
        LD      HL,(0A604h)     ; Pointer to start of Speech Buffer
        ADD     HL,DE           ; HL = Goto end of speech buffer
;----------------------------------------------------
;        Make sure character is between "A"-"Z"
;----------------------------------------------------
L2685:  PUSH    HL              ; Save pointer to Speech Buffer       
        PUSH    DE              ; Save loop counter
        LD      A,(HL)          ; Get character from speech buffer
        CP      041h            ; Is character > "A"?
        JR      C,L26A7         ; No, so use default code       
        CP      05Bh            ; Is character < "Z+"
        JR      NC,L26A7        ; No so use default code       
;----------------------------------------------------
;     Get Character Classification Symbol (A200)
;----------------------------------------------------
        SUB     041h            ; Get character number
        LD      E,A             ; DE = Character number (1-26)
        LD      HL,L26B3        ; Point to Character Classification Table
        ADD     HL,DE           ; Index into table
        LD      A,(HL)          ; Get classification symbol from table
        LD      HL,0A200h       ; Point to A200 
        POP     DE              ; Restore loop counter
        ADD     HL,BC           ; Index into A200 area
        LD      (HL),A          ; Save classification symbol
        POP     HL              ; Restore pointer to Speech Buffer
;----------------------------------------------------
;      Decrement loop and continue checking buffer
;----------------------------------------------------
L269F:  DEC     HL              ; Point to next character in buffer
        DEC     C               ; Decrement character count
        LD      A,C             ; Get character count
        CP      0FFh            ; Is remaining character count at zero?
        JR      NZ,L2685        ; No, so loop back
        RET                     ; Return

;----------------------------------------------------
;  Store *out-of-range* Speech Control Code at A200
;----------------------------------------------------
L26A7:  LD      A,021h          ; Default control code ("!")
        LD      HL,0A200h       ; Point to A200 control codes
        ADD     HL,BC           ; Index into A200 control area
        LD      (HL),A          ; Save Speech Control Code
        POP     DE              ; Restore loop count
        POP     HL              ; Restore pointer to Speech Buffer 
        JP      L269F           ; Continue with loop







;----------------------------------------------------
;        A200 Character Classification Symbols
;----------------------------------------------------
;      (#)    A,O,U
;      (+)    E,I,Y
;      (.)    B,D,G,J,L,M,N,R,V,W,Z
;      ( )    C,F,H,K,P,Q,S,T,X
;----------------------------------------------------
L26B3:   DB   023h   ; "#"  A
         DB   02Eh   ; "."  B
         DB   05Eh   ; " "  C 
         DB   02Eh   ; "."  D
         DB   02Bh   ; "+"  E
         DB   05Eh   ; " "  F
         DB   02Eh   ; "."  G
         DB   05Eh   ; " "  H
         DB   02Bh   ; "+"  I
         DB   02Eh   ; "."  J
         DB   05Eh   ; " "  K
         DB   02Eh   ; "."  L
         DB   02Eh   ; "."  M
         DB   02Eh   ; "."  N
         DB   023h   ; "#"  O
         DB   05Eh   ; " "  P
         DB   05Eh   ; " "  Q
         DB   02Eh   ; "."  R
         DB   05Eh   ; " "  S
         DB   05Eh   ; " "  T
         DB   023h   ; "#"  U
         DB   02Eh   ; "."  V
         DB   02Eh   ; "."  W
         DB   05Eh   ; " "  X
         DB   02Bh   ; "+"  Y
         DB   02Eh   ; "."  Z










;----------------------------------------------------
;            Apply Voice Characteristics
;----------------------------------------------------
L26CD:  LD      HL,0A400h       ; HL = A400 
        LD      (0A60Eh),HL     ; Reset Phoneme pointer
        LD      (0A610h),HL     ; Reset Phoneme pointer
;----------------------------------------------------
;         Erase Voice Variables (A622-A641)
;----------------------------------------------------
        LD      HL,0A622h       ; Start of variables to clear
        LD      B,01Fh          ; 31 bytes to erase
        SUB     A               ; A = 0
L26DC:  LD      (HL),A          ; Erase byte
        INC     HL              ; Go to next byte
        DJNZ    L26DC           ; Loop until all bytes erased
;----------------------------------------------------
;           Setup Speech Rates (A200)
;----------------------------------------------------               
        LD      A,(029EFh)      ; Get default Speech Rate (09h) 
        ADD     A,A             ; Shift bits left (shift it to the upper nibble)
        ADD     A,A             ; Shift bits left
        ADD     A,A             ; Shift bits left
        ADD     A,A             ; Shift bits left
        OR      008h            ; Add control bit to lower nibble (098h)
        LD      (0A630h),A      ; Save Speech Rate Low (098h)
        ADD     A,010h          ; Add 1 to rate, Speech Rate High (0A8h)
        LD      (0A62Ch),A      ; Save Speech Rate High (0A8h) copy of A628
        LD      (0A628h),A      ; Initialize Speech Rate to High (0A8h)
;----------------------------------------------------
;            Setup Amplitude (Volume) (A300)
;----------------------------------------------------
        LD      A,(029F0h)      ; Get default Amplitude (00Ch)
        OR      060h            ; Add control bit (06Ch)
        LD      (0A62Bh),A      ; Save Amplitude Level Low
        LD      (0A627h),A      ; Save Amplitude Level Low (copy)
        ADD     A,003h          ; Add 3 to level, Amplitude Level High (06Fh)
        LD      (0A62Fh),A      ; Save Amplitude Level High
;----------------------------------------------------
;            Setup Filter Frequency (A000)
;---------------------------------------------------
        LD      A,(029F1h)      ; Get default Filter Frequency Low (0E6h)
        LD      (0A62Ah),A      ; Save Filter Frequency Low
        LD      (0A626h),A      ; Save Filter Frequency Low (copy)
        ADD     A,001h          ; Add 1 to value, Filter Frequency High
        LD      (0A62Eh),A      ; Save Filter Frequency High (0E7h)
;----------------------------------------------------
;            Setup Inflection Levels (A100) 
;----------------------------------------------------
        LD      A,(029EEh)      ; Get default Inflection Level pointer (008h)
        LD      E,A             ; Setup index into Inflection Table 
        LD      D,000h          ; DE = Index into Inflection Table
        LD      HL,029CFh       ; Get pointer to Inflection Table 
        ADD     HL,DE           ; Index into Table 
        LD      A,(HL)          ; Get Inflection Level (046h)
        LD      (0A622h),A      ; Save Inflection Level 1 (046h)
        ADD     A,018h          ; Add 018h for next level
        LD      (0A623h),A      ; Save Inflection Level 2 (05Eh)
        ADD     A,018h          ; Add 018h for next level
        LD      (0A624h),A      ; Save Inflection Level 3 (076h)
        ADD     A,018h          ; Add 018h for next level
        LD      (0A625h),A      ; Save Inflection Level 4 (08Eh)

;----------------------------------------------------
;         Setup Voice Characterizing Loop
;---------------------------------------------------
L272F:  LD      A,(0A639h)      ; Get main loop (initially zero)
        LD      C,A             ; C = Loop
        LD      E,A             ; E = Loop
        LD      D,000h          ; DE = Loop
        LD      HL,(0A610h)     ; A400 pointer
        ADD     HL,DE           ; Index into A400 table
;----------------------------------------------------
;       Main Loop - Check for inflection change (FC)
;----------------------------------------------------
L273A:  LD      A,(HL)          ; Get Voice control code (A400)
        CP      0FCh            ; Is there an inflection change?
        JR      NZ,L2750        ; No, so skip ahead
;----------------------------------------------------
;         Increase inflection and amplitude
;----------------------------------------------------               
        LD      A,(0A634h)      ; Get voice volume
        INC     A               ; Increase voice volume
        LD      (0A634h),A      ; Save new voice volume
        LD      A,(0A63Bh)      ; Get voice volume
        INC     A               ; Increase voice volume
        LD      (0A63Bh),A      ; Save new voice volume
        JP      L2754           ; Skip ahead and increase ?
;----------------------------------------------------
;          Check for inflection change (F9)
;----------------------------------------------------
L2750:  CP      0F9h
        JR      NC,L277C        ; Process Equation Code       
L2754:  INC     HL
        INC     C
        EX      DE,HL
        LD      HL,(0A608h)
        LD      A,E
        CP      L
        JR      C,L2761                 
        JP      L2765           ; Use Equation #2
L2761:  EX      DE,HL           ; Next byte
        JP      L273A           ; Loop back
;----------------------------------------------------
;            Setup to use Equation #2
;----------------------------------------------------
L2765:  INC     HL              ; Next byte (A400)
        LD      (0A608h),HL     ; Save HL (A400)
        LD      A,0FBh          ; Equation code FB = #2
        JP      L277C           ; Process Equation Code 

;----------------------------------------------------
;            Set stuff then return
;----------------------------------------------------
L276E:  LD      A,(0A63Bh)      ;
        LD      B,A             ;
        LD      HL,(0A608h)     ;
        LD      A,L             ;
        SUB     B               ;
        LD      L,A             ;
        LD      (0A608h),HL     ;
        RET                     ; Process done, return to speech routine




;----------------------------------------------------
;                Equation stuff
;----------------------------------------------------
;       C = number?
;       A = Equation code to use
;           F9 Equation #
;           FA Equation #
;           FB Equation #2
;----------------------------------------------------
L277C:  LD      (0A63Ch),A      ; Save Equation Code
        LD      A,C
        LD      (0A639h),A
        LD      A,(0A634h)
        SRL     A
        CP      002h
        JR      C,L279E                 
        LD      A,(0A623h)
        LD      (0A62Dh),A
        LD      (0A632h),A
        LD      A,(0A625h)
        LD      (0A631h),A
        JP      L27AD

L279E:  LD      A,(0A623h)
        LD      (0A62Dh),A
        LD      (0A632h),A
        LD      A,(0A624h)
        LD      (0A631h),A

L27AD:  LD      A,(0A63Ch)      ; Get Equation Code
        CP      0F9h
        JR      Z,L27C3         ; Use equation #0       
        CP      0FAh
        JR      Z,L27CB         ; Use equation #1       
        CP      0FBh
        JR      Z,L27D3         ; Use equation #2       
        CP      0FFh
        JR      Z,L27EB         ; Use equation #3       
        JP      L276E           ; Finish up and return
;----------------------------------------------------
;            Use Equation #0
;----------------------------------------------------
L27C3:  LD      E,000h          ; Equation #0
        CALL    L299A           ; Read equation
        JP      L27D8           ; Skip ahead
;----------------------------------------------------
;            Use Equation #1
;----------------------------------------------------
L27CB:  LD      E,001h          ; Equation #1
        CALL    L299A           ; Read equation
        JP      L27D8           ; Skip ahead
;----------------------------------------------------
;            Use Equation #2
;----------------------------------------------------
L27D3:  LD      E,002h          ; Equation #2
        CALL    L299A           ; Read equation
;----------------------------------------------------
;             Continue with Equation
;----------------------------------------------------
L27D8:  LD      A,(0A622h)      ;
        LD      (0A633h),A      ;
        LD      A,(0A632h)      ;
        LD      (0A629h),A      ;
        SUB     A               ;
        LD      (0A638h),A      ;
        JP      L2801           ;

L27EB:  LD      E,003h          ;
        CALL    L299A           ;
        LD      A,(0A625h)      ;
        LD      (0A633h),A      ;
        LD      A,(0A632h)
        LD      (0A629h),A
        LD      A,001
        LD      (0A638h),A

L2801:  LD      A,(0A63Eh)
        LD      C,A
        LD      B,000h
        LD      IY,(0A60Eh)
        ADD     IY,BC
        LD      A,(0A63Fh)
        LD      E,A
        LD      D,000h
        LD      HL,0A400h
        ADD     HL,DE
        LD      B,E             ;
        PUSH    BC              ;

;----------------------------------------------------
;             Start Equation Loop
;----------------------------------------------------
L2819:  LD      A,(IY+000h)     ;
        CP      0FCh            ;
        JR      NZ,L2823        ;       
        JP      L291D           ;

L2823:  CP      0F9h
        JR      C,L282A                 
        JP      L289F

L282A:  LD      (HL),A
        LD      A,(0A635h)
        OR      A
        JR      Z,L2877                 
        LD      A,(0A638h)
        OR      A
        JR      Z,L284B                 
        LD      A,(0A633h)
        LD      C,A
        LD      A,(0A629h)
        CP      C
        JR      Z,L285F                 
        JR      NC,L285F               
        ADD     A,008h
        LD      (0A629h),A
        JP      L2865

L284B:  LD      A,(0A633h)
        LD      C,A
        LD      A,(0A629h)
        CP      C
        JR      C,L285F                 
        JR      Z,L285F                 
        SUB     008h
        LD      (0A629h),A
        JP      L2865

L285F:  LD      A,(0A633h)
        LD      (0A629h),A

L2865:  LD      A,(0A62Ch)
        LD      (0A628h),A
        LD      A,(0A62Bh)
        LD      (0A627h),A
        LD      A,(0A62Ah)
        LD      (0A626h),A
L2877:  DEC     H
;----------------------------------------------------
;        Replace all codes with new match (?)
;               A629 --> A300
;               A628 --> A200
;               A627 --> A100
;               A626 --> A000
;----------------------------------------------------
        LD      A,(0A629h)      ; Get new code
        LD      (HL),A          ; Replace A300 code
        DEC     H               ; Next bank
        LD      A,(0A628h)      ; Get new code
        LD      (HL),A          ; Replace A200 code
        DEC     H               ; Next bank
        LD      A,(0A627h)      ; Get new code 
        LD      (HL),A          ; Replace A100 code
        DEC     H               ; Next bank
        LD      A,(0A626h)      ; Get new code
        LD      (HL),A          ; Replace A000 code
        LD      A,H             ; Return to beginning
        ADD     A,004h          ; Go back to A400
        LD      H,A             ; HL = A4xx
        INC     HL              ; Point to next byte
        INC     IY
        POP     BC
        INC     B               ;
        INC     C               ;
        PUSH    BC              ;
        LD      A,(0A639h)
        LD      E,A
        LD      A,C
        CP      E
        JP      C,L2819

L289F:  POP     BC
        INC     C
        INC     IY
        PUSH    BC
        LD      A,(0A63Ah)      ; Get characters right of equals sign
        OR      A               ; Are there any?
        JR      Z,L28EA         ; No, so leave       

L28AA:  LD      A,(IY+000h)
        LD      (HL),A
        DEC     H
        LD      A,(0A633h)
        LD      (HL),A          ; Replace A300 code
        DEC     H               ; Next bank
        LD      A,(0A628h)      ; Get new code
        LD      (HL),A          ; Replace A200 code
        DEC     H               ; Next bank
        LD      A,(0A627h)      ; Get new code
        LD      (HL),A          ; Replace A100 code
        DEC     H               ; Next bank
        LD      A,(0A626h)      ; Get new code
        LD      (HL),A          ; Replace A000 code
        INC     IY              ; Next byte
        INC     HL              ; Next byte
        LD      A,H
        ADD     A,004h
        LD      H,A

        POP     BC              ; Get counter
        INC     B               ; Increment counter
        INC     C               ; Increment counter
        PUSH    BC              ; Save counter
        LD      A,(0A63Ah)      ; Get characters right of equals sign
        LD      E,A             ; E = characters right of equals sign
        LD      A,(0A63Dh)
        INC     A
        LD      (0A63Dh),A
        CP      E
        JR      C,L28AA         ; Loop back until all bytes replaced       
        JR      Z,L28AA 
               
;----------------------------------------------------
;        Finished replace codes for word
;----------------------------------------------------                       
        LD      HL,(0A608h)     ;
        LD      A,C             ;
        CP      L               ;
        JR      C,L28EA         ;       
        JR      Z,L28EA         ;       
        POP     BC              ;
        JP      L276E           ; Finish up and return

L28EA:  POP     BC
        DEC     B
        DEC     C
        LD      A,C
        LD      (0A63Eh),A
        LD      (0A639h),A
        LD      A,B
        LD      (0A63Fh),A
        SUB     A
        LD      (0A634h),A
        LD      (0A637h),A
        LD      (0A63Ah),A
        LD      (0A63Dh),A
        LD      (0A635h),A
        LD      A,(0A62Ch)
        LD      (0A628h),A
        LD      A,(0A62Bh)
        LD      (0A627h),A
        LD      A,(0A62Ah)
        LD      (0A626h),A
        JP      L272F

L291D:  LD      A,(0A636h)
        OR      A
        JR      Z,L295C                 
        DEC     A
        LD      (0A636h),A
        LD      A,(0A637h)
        INC     A
        LD      (0A637h),A
        LD      C,A
        LD      A,(0A634h)
        LD      B,A
        LD      A,C
        CP      B
        JR      Z,L2954                 
        JR      NC,L2954               
        LD      A,(0A62Dh)
        LD      (0A629h),A
        LD      A,(0A62Ch)
        LD      (0A628h),A
        LD      A,(0A62Bh)
        LD      (0A627h),A
        LD      A,(0A62Ah)
        LD      (0A626h),A
        JP      L2992

L2954:  LD      A,001h
        LD      (0A635h),A
        JP      L2992

L295C:  LD      A,(0A631h)
        LD      (0A629h),A
        LD      A,(0A630h)      ; Get 098h
        LD      (0A628h),A
        LD      A,(0A62Fh)
        LD      (0A627h),A
        LD      A,(0A62Eh)
        LD      (0A626h),A
        LD      A,(0A636h)
        INC     A
        LD      (0A636h),A
        LD      A,(0A637h)
        INC     A
        LD      (0A637h),A
        LD      A,(0A625h)
        LD      C,A             ;
        LD      A,(0A629h)      ;
        CP      C               ;
        JR      NZ,L2992        ;       
        LD      A,(0A624h)      ;
        LD      (0A631h),A

L2992:  INC     IY
        POP     BC
        INC     C
        PUSH    BC
        JP      L2819









;----------------------------------------------------
;              Analyze Word Phonemes
;----------------------------------------------------
;         E = Word equation number (0,1,2,3)
;----------------------------------------------------
L299A:  LD      D,000h          ; DE = Equation Number
        LD      HL,L29EA        ; Point to data jumpers
        ADD     HL,DE           ; Add equation number
        LD      A,(HL)          ; Get data jumper
        SUB     020h            ; Subtract 32 for some reason
        ADD     A,A             ; Multiply by 2 for table
        LD      E,A             ; E = result
        LD      HL,029F2h       ; Point to Equation Pointers
        ADD     HL,DE           ; Add jumper 
        LD      A,(HL)          ; Get low-byte address
        LD      (0A60Ch),A      ; Save low-byte addres
        INC     HL              ; Point to high-byte address
        LD      A,(HL)          ; Get high-byte address
        LD      (0A60Dh),A      ; Save high-byte address
;----------------------------------------------------
;   Count phonemes to the left of the equals sign
;----------------------------------------------------
        LD      HL,(0A60Ch)     ; HL = Equation Pointer
        LD      A,(HL)          ; Get first byte of equation
        LD      E,A             ; E = Number of bytes in total equation
        INC     HL              ; Point to next byte in equation
        LD      C,001h          ; Count number of bytes left of equals sign
L29BA:  LD      A,(HL)          ; Get next byte in equations
        CP      03Dh            ; Check for equals sign (=)
        JR      Z,L29C4         ; Equal sign has been found, so skip ahead       
        INC     HL              ; No equals sign so check next byte
        INC     C               ; Increment number of bytes of left equals sign
        JP      L29BA           ; Continue checking for equals sign (=)
;----------------------------------------------------
;               Equals sign found 
;----------------------------------------------------
L29C4:  INC     C               ; Sum number of bytes until equals sign
        LD      A,E             ; A = length of phoneme equation
        SUB     C               ; Subtract characters left of equals sign
        LD      (0A63Ah),A      ; Save number of characters right of equals sign
        LD      HL,0A63Bh       ; Point to ??
        INC     (HL)            ; Increment ??
        RET                     ; Return







;----------------------------------------------------
;            Inflection Level Data Table 
;----------------------------------------------------
L29CF:   DB  006h00Eh016h01Eh026h02Eh036h03Eh046h                 
         DB  04Eh056h05Eh066h06Eh076h07Eh086h08Eh
         DB  096h09Eh0A6h0AEh0B6h0BEh0C6h0CEh0D6h

;----------------------------------------------------
;             Base Equations Pointers
;----------------------------------------------------
L29EA:   DB  021h
         DB  02Ch
         DB  02Eh   ; Equation #2  2A8Dh
         DB  03Fh

;----------------------------------------------------
;               Default Voice Settings
;----------------------------------------------------
L29EE:   DB    8   ; Inflection (0-26) 
L29EF:   DB    9   ; Speech Rate (0-13) 
L29F0:   DB   12   ; Amplitude (Volume) (0-11)
L29F1:   DB  230   ; Filter Frequency (0-253)

;----------------------------------------------------
;             Phonetic Rule Pointers (64)
;----------------------------------------------------
L29F2:   DW  02A74h02A8Dh02A72h02A72h
         DW  02A72h02A72h02A72h02A77h
         DW  02A72h02A72h02A72h02A72h
         DW  02A89h   ; 2C base equation 
         DW  02A72h02A8Dh02A72h

         DW  02A92h   ; Number "0" Rule
         DW  02A9Bh   ; Number "1" Rule
         DW  02AA3h   ; Number "2" Rule
         DW  02AAAh   ; Number "3" Rule
         DW  02AB2h   ; Number "4" Rule
         DW  02ABAh   ; Number "5" Rule
         DW  02AC3h   ; Number "6" Rule
         DW  02ACCh   ; Number "7" Rule
         DW  02AD6h   ; Number "8" Rule
         DW  02ADEh   ; Number "9" Rule

         DW  02A72h02A72h02A72h02A72h02A72h
         DW  02A8Dh02A72h   

         DW  02AE7h   ; Letter "A" Rules
         DW  03045h   ; Letter "B" Rules
         DW  0321Eh   ; Letter "C" Rules
         DW  03501h   ; Letter "D" Rules
         DW  036E1h   ; Letter "E" Rules
         DW  03B6Bh   ; Letter "F" Rules
         DW  03BE8h   ; Letter "G" Rules
         DW  03DBDh   ; Letter "H" Rules
         DW  03F36h   ; Letter "I" Rules
         DW  042E6h   ; Letter "J" Rules
         DW  043D0h   ; Letter "K" Rules
         DW  0444Eh   ; Letter "L" Rules
         DW  045C1h   ; Letter "M" Rules
         DW  0480Bh   ; Letter "N" Rules
         DW  04935h   ; Letter "O" Rules
         DW  04D01h   ; Letter "P" Rules
         DW  04F12h   ; Letter "Q" Rules
         DW  04F87h   ; Letter "R" Rules
         DW  05146h   ; Letter "S" Rules
         DW  05495h   ; Letter "T" Rules
         DW  057B4h   ; Letter "U" Rules
         DW  05943h   ; Letter "V" Rules
         DW  059CFh   ; Letter "W" Rules
         DW  05B28h   ; Letter "X" Rules
         DW  05B64h   ; Letter "Y" Rules
         DW  05C55h   ; Letter "Z" Rules

         DW  02A72h02A72h02A72h02A72h02A72h
         
;----------------------------------------------------
;             Phoneme Definitions
;----------------------------------------------------
;                  Consonants         
;----------------------------------------------------
_B    EQU    024h ; bat, tab
_D    EQU    025h ; dub, bud
_F    EQU    034h ; fat, ruff, photo, laugh
_HV   EQU    02Ah ; eh!
_HVC  EQU    02Bh ; d(h)ouble
_HF   EQU    02Ch ; hat, home       
_HFC  EQU    02Dh ; P(h)ad, fluff(h), black(h)     
_HN   EQU    02Eh ; hnh-hnh
_J    EQU    031h ; job, rage       
_K    EQU    029h ; kit, tick
_KV   EQU    026h ; big, gag
_L    EQU    020h ; lab, ball
_LI   EQU    021h ; plan, club, slam
_LF   EQU    022h ; bott/e, channe/
_M    EQU    037h ; mad, dam
_N    EQU    038h ; not, ton       
_NG   EQU    039h ; ring, rang
_P    EQU    027h ; pat, tap
_R    EQU    01Dh ; rat
_S    EQU    030h ; sat, lass
_SCH  EQU    032h ; shop, push
_T    EQU    028h ; tap, pat
_THV  EQU    035h ; bathe, the
_TH   EQU    036h ; bath, theory
_V    EQU    033h ; vow, pave
_W    EQU    023h ; why, quake
_Y1   EQU    004h ; you
_Z    EQU    02Fh ; zap, maze

;----------------------------------------------------
;                 Vowels         
;----------------------------------------------------
_A    EQU    008h ; day         
_AI   EQU    009h ; care
_AE   EQU    00Ch ; dad
_AEI  EQU    00Dh ; laugh
_AH   EQU    00Eh ; top, about
_AHI  EQU    00Fh ; father
_AW   EQU    010h ; saw, caught
_E    EQU    001h ; beet, be
_EI   EQU    002h ; advent
_EH   EQU    00Ah ; leg, said
_EHI  EQU    00Bh ; silent
_ER   EQU    01Ch ; third, urn, heard
_I    EQU    007h ; sit, bid
_O    EQU    011h ; boat
_OO   EQU    013h ; put, pull, look
_OU   EQU    012h ; orb
_U    EQU    016h ; boot, you
_UI   EQU    017h ; poor
_UH   EQU    018h ; cup
_UH1  EQU    019h ; circus
_UH2  EQU    01Ah ; nation
_UH3  EQU    01Bh ; nation
   
   
;----------------------------------------------------
;                 Foreign Sounds         
;----------------------------------------------------       
_AY   EQU    005h ; francais    French
_A1   EQU    03Ah ; etre        French or umlauted A in German
_E2   EQU    03Eh ; schön       German
_IE   EQU    006h ; il          French
_IU   EQU    014h ; peut        French
_IUI  EQU    015h ; Goethe      German
_OH   EQU    03Bh ; menu, tu    French
_U2   EQU    03Ch ; fiihlen     German
_UH4  EQU    03Dh ; menu, tu    French
_Y    EQU    003h ; y           French
_LB   EQU    03Fh ; il          French
_Rl   EQU    01Eh ; réponse     French
_R2   EQU    01Fh ; richtig     German
 


;----------------------------------------------------
;              General Phonetic Rules
;----------------------------------------------------
L2A72:   DB  2"="
L2A74:   DB  3"="040h
L2A77:   DB  9"S('S)=" ,04Ah, _Z
L2A80:   DB  7"('S)=", _Z
L2A87:   DB  2"="
L2A89:   DB  4"="000h000h        ; Double <PAUSE>                     
L2A8D:   DB  5"="000h000h000h  ; Triple <PAUSE>  Equation #2

;----------------------------------------------------
;                Number Phonetic Rules
;----------------------------------------------------
;         #bytes  Rule     Phonetics
;----------------------------------------------------
L2A92:   DB  9"(0)=",_Z,_EI,_ER,_O
L2A9B:   DB  8"(1)=",_W,_AH,_N
L2AA3:   DB  7"(2)=",_T,_U
L2AAA:   DB  8"(3)=",_TH,_ER,_E
L2AB2:   DB  8"(4)=",_F,_O,_ER
L2ABA:   DB  9"(5)=",_F,_AHI,_E,_V             
L2AC3:   DB  9"(6)=",_S,_I,_K,_S 
L2ACC:   DB  10"(7)=",_S,_EHI,_V,_EHI,_N
L2AD6:   DB  8"(8)=",_EHI,_E,_T
L2ADE:   DB  9"(9)=",_N,_AHI,_Y,_N

;----------------------------------------------------
;                 "A" Phonetic Rules
;----------------------------------------------------
L2AE7:   
   DB   9,   "!(A)!=",8,4
   DB   7,   "(A)!=",1Ah
   DB   14"!(AARON)=",0Ch,1Dh,047h,038h
   DB   7,   "(AA)=",0Eh
   DB   16"!(ABI)GAIL!=",0Ch,"$",047h
   DB   9,   "!(A)BO=",18h
   DB   12"!(A)CROSS=",18h
   DB   25"!(ACTIVITIES)=LL)(H3H(",1,"/"
   DB   14"!(ADAM)=LL",025h,"X7"   
   DB   15"!(AFRI)CA=",0Ch,"4",1Dh,047h
   DB   14"(AGAIN)=",1Ah,"»",0Ah038h
   DB   12"#:(AG)E=",7,041h,"1"
   DB   14"!(AGO)!=XT",0E6h,11h,"c"
   DB   18"!(AGREED)=",18h,0E9h,0E6h,1Dh,1,"A",041h
   DB   14"!(AHEAD)=",18h,"¼",0Ah,041h
   DB   12"OUNT(AI)N=",0Ah
   DB   11"#: (AI)N=",0Ah
   DB   8,   "(A)IR=",8
   DB   10"(AI).=HH",4
   DB   8,   "(AI)=",8,4
   DB   13"!(ALAN)=",0Ch," ",047h,038h
   DB   10"(AL)F!=îL"
   DB   15"!(ALICE)!=",0Ch," ",047h,"0"
   DB   9,   "(AL)K=PP"
   DB   19"!(ALLISON)!=",0Ch," ",047h,"0X",038h
   DB   10"#:(A)LLY="
   DB   15"!(ALON)E=X ",11h,"c",038h
   DB   10"#:(AL)!= "
   DB   12"#:(ALS)!= /"
   DB   9,   "(AL)M=PP"
   DB   9,   "(AL)V=LL"
   DB   9,   "(A)LLI=",0Dh
   DB   9,   "(A)L.=PP"
   DB   9,   "(A)LL=PP"
   DB   8,   "(A)L =",10h
   DB   9,   "!(A)L#=",1Ah
   DB   18"!(AMANDA)!=X7",0Ch038h,041h,"X"
   DB   10"(A)MENT=N"
   DB   21"!(AMERICAN)=X",038h,0Ah,1Dh,047h,")",047h,038h
   DB   11"!(A)MONG=",18h
   DB   13"!(AM)OUNT=",18h,"7"
   DB   13"!(AMY)!=",8,"ä7",1
   DB   19"!(ANDREA)!=NN8",041h,1Dh,1,"X"
   DB   9,   "!(A)ND=",0Ah
   DB   12"#:(A)NCE!=",0Ah
   DB   20"!(ANCIENT)=",8,"ä8h2",047h,038h,"("
   DB   17"!(ANGELA)=",0Ch,038h,"1",047h," X"
   DB   12"(ANG)+=",8,4,038h,"1"
   DB   16"!(ANIMAL)=",0Ch,038h,047h,038h," "
   DB   16"!(ANITA)!=X",038h,1,"(X"
   DB   11"# (A)NT!=G"
   DB   10"  (A)NT=J"
   DB   18"!:(ANYONE)=",0Ah,038h,1,"c",18h,038h
   DB   10"!:(A)NY=",0Ah
   DB   15"!(APART)=X",27h,0Eh,05Ch,"("
   DB   18"!(APPEARED)=X",27h,1,05Ch,041h
   DB   15"!(APPEAR)=X",27h,1,05Ch
   DB   12"!:(AR)!=NN",05Ch
   DB   8,   "(AR)!=",1Ch
   DB   11" (ARA)=",0Bh,05Ch,"î"
   DB   10"(AR)D=NN",05Ch
   DB   12"!(ARE)!=NN",05Ch
   DB   13"!(ARE)N",27h,"T=",0Fh,"£"
   DB   9,   "!(A)RO=",1Ah
   DB   10"!(A)RRO=",0Ch
   DB   9,   "!(A)RR=",1Ah
   DB   8,   "(A)RR=",0Ch
   DB   9,   "(AR)#=",8,05Ch
   DB   10"(AR).=NN",05Ch
   DB   8,   "(AR)=",0Eh,05Ch
   DB   14"!(ASIA)=",8,"äo2X"
   DB   10"!(A)SS#=",0Eh
   DB   11"! (A)S#=",8,4
   DB   13"(ATEAU)=",0Ch,"(",11h,"c"
   DB   11"(ATE)=",8,"ä(+"
   DB   12"(ATH)E!=HH5"
   DB   9,   "(A)TIN=",0Ch
   DB   14"! (A)TIONAL=",0Ch
   DB   22"!(ATLANTIC)=",0Dh,"( ",0Ch,"L8(",047h,")"
   DB   13"!(ATOM)=",0Ch,"(",18h,"7"
   DB   10"(A)TORY=X"
   DB   10"(A)TURE=",18h
   DB   11"(AUSE)=PP/"
   DB   9,   "(AU).=PP"
   DB   25"!(AUTOMOBILE)=",10h,"(",11h,"c7",11h,"c$",1," "
   DB   7,   "(AU)=",10h
   DB   8,   "(A)WA=",1Ah
   DB   8,   "(AW)=PP"
   DB   13"(AXES)=",0Ch,")0",047h,"/"
   DB   8,   "!(A)X=",0Ch
   DB   9,   "(AY)=HH",4
   DB   10"(A) ACE=",0Eh
   DB   10"(A) AT=LL"
   DB   12"(A) EFUL=",8,4
   DB   13"(A) EMENT=",8,4
   DB   10"(A) ET=LL"
   DB   10"(A) ID=LL"
   DB   11"(A) ISH=LL"
   DB   10"(A) IT=LL"
   DB   11"(A) ITE=LL"
   DB   10"(A) OON=",0Ch,0Dh,"(A) OROUS=LL"
   DB   10"(A) OT=LL"
   DB   10"!(A) T#=",0Ch
   DB   10"(A) UT=LL"
   DB   11"!(A): ##=",0Eh
   DB   10"(A) +#=",8,4
   DB   10"(A) +:#=",0Ch
   DB   11" (A) IC=îL"
   DB   10":(A) #=",8,4
   DB   12"!:(A) L#=",8,4
   DB   10"(A) RIC=",0Ch
   DB   12"!:(A) R#=",8,4
   DB   9,   "(A) LE=",1Bh
   DB   11"(A) RE!=HH"
   DB   8,   "(A).=L",0Ch
   DB   6,   "(A)=",0Ch
 
     
   DB   9,   "!(B)!=$",1
   DB   18"!(BALANCE)=$",0Dh," ",047h,038h,"0"
   DB   19"!(BARBARA)!=$",0Eh,05Ch,"$",1Dh,"X"
   DB   12"!(BEAR)=$",0Ah,05Ch
   DB   13"!(BED):=$JJ",041h
   DB   13"!(BENE)=$",0Ah,038h,7
   DB   21"!(BENJAMIN)=$",0Ah,038h,"1X7",047h,038h
   DB   12"!(BE): #=$A"
   DB   11"(BE)ING=$",1
   DB   18"!(BERNICE)!","=$",1Ch,038h,1,"0"
   DB   12"!(BIG)=$",7,0E6h,"+"
   DB   16"!(BILLIE)!=$",047h," ",1
   DB   13"!(BI) #=$NNä"
   DB   10"(BIO)=$",1,0Eh
   DB   11"!(BI)#=$",0Eh,"ä"
   DB   13"!(BONE)=$",11h,"c",038h
   DB   13"!(BO)TH!=$QQ"
   DB   14"(BOUGH)!=$NN",16h
   DB   11"(BOW)L=$QQ"
   DB   10"(BOW)=$",10h,16h
   DB   19"!(BRADLEY)!=$",1Dh,0Ch,041h,"`",1
   DB   18"!(BRANDI)!=$",1Dh,0Ch,038h,041h,1
   DB   18"!(BRANDON)=$",1Dh,0Ch,038h,041h,038h
   DB   13"!(BREA)K=$",1Dh,8
   DB   12"(BROW)=$"1Dh,10h,16h
   DB   7,   "(BT)=("
   DB   18"!(BUSIN)ESS=$",7,"/",047h,038h
   DB   12"!(BUS)#=$",7,"/"
   DB   8,   "!(B)L=$"
   DB   15"!(BRIA)N=$",1Dh,0Eh,"ä",047h
   DB   8,   "!(B)R=$"
   DB   8,   "!(B): ="
   DB   10"M(B)ING!="
   DB   8,   "M(B)S!="
   DB   7,   "M(B)!="
   DB   7,   "(BB)=$"
   DB   10"!(BY)=$",0Eh,4
   DB   6,   "(B)=$"
 
     
   DB   9,   "!(C)!=0",1
   DB   15"!(CABIN)=)",0Ch,"$",047h,038h
   DB   14"!(CAL)VIN=)",0Ch,"`"
   DB   13"!(CAPI)=)",0Ch,27h,047h
   DB   21"!(CAROLINE)!=)",0Ch,1Dh,"X ",047h,038h
   DB   21"!(CATHERINE)!=)",0Ch,"6",1Dh,047h,038h
   DB   9,   "(CC)+=)0"
   DB   10"(CEA)N=2",18h
   DB   11"(CES)!=0K/"
   DB   17"!(CERTAIN)=0",1Ch,"h",0Ah038h
   DB   7,   "EX(C)="
   DB   22"!(CHRISTIN)#!=)",1Dh,047h,"0(",1,038h
   DB   9,   "!(CH) =)"
   DB   15"!(CH)ARACTER=)"
   DB   19"!(CHARLES)!=(2",0Eh,05Ch,"`/"
   DB   17,   "!(CHERYL)!=2",0Ah1Dh,047h," "
   DB   16"!(CHINA)=(2",0Eh,"ä8X"
   DB   15"!(CHOIR)=)c",0Eh,"ä",05Ch
   DB   10"!(CH)OR=)"
   DB   9,   " +(CH)=)"
   DB   10"(CH)!=(2Ç"
   DB   8,   "(CH)=(2"
   DB   13"!S(CI)#=0NNä"
   DB   9,   "(CI)AL=2"
   DB   11"(CIA)N!=2",18h
   DB   9,   "(CI)A=2",1
   DB   16"!(CINDY)!=0",047h,038h,041h,01h
   DB   8,   "(CI)O=2"
   DB   9,   "(CI)EN=2"
   DB   18"!(CITIZEN)=0",047h,"(",047h,"/",038h
   DB   7,   "(C)+=0"
   DB   9,   "(CKG)=",0E6h,"+"
   DB   9,   "(CK)=)¡+"
   DB   16"!(CLARA)!=) ",0Ch,1Dh,"X"
   DB   16"!(CLE)MENT!=) ",0Ah
   DB   19"!(CLIMATE)=) ",0Eh,"ä7",047h,"("
   DB   15"!(CLIMB)=) ",0Eh,"ä7"
   DB   18"!(COMPAN)Y=)",18h"7",27h,047h,038h
   DB   11"(CO)M=)¡ZZ"
   DB   16"!(CONNIE)!=)",0Eh,038h,1
   DB   20"!(CONSIDER)=)",18h,038h,"0",047h,041h,1Ch
   DB   20"!(CONTAIN)=)¡",18h,038h,"(",8,"ä",038h
   DB   11"!(CO)PY=)",0Eh
   DB   13"(CO)ST=",")¡+PP"
   DB   14"(COU)NTR+=)¡",18h
   DB   14"(COUR)SE=)¡",11h,1Ch
   DB   13"(COUS)IN=)",18h,"/"
   DB   10"(COW)=)Oc"
   DB   14"(CRACY)=)",1Dh,18h,"0",1
   DB   13"(CREA)TU=)",1Dh,1
   DB   15"(CREA)T#=)",1Dh,1,8,4
   DB   16"!(CRIED)!=)",1Dh,0Eh,"ä",041h
   DB   9,   "!(CZ)#=/"
   DB   10"!(CZ)+=(2"
   DB   8,   "!(C)=)-"
   DB   7,   "(CC)=i"
   DB   6,   "(C)=)"
 
   
   DB   9,   "!(D)!=",041h,1
   DB   16"!(DANIE)L=",041h,0Ch,038h,"ä",047h
   DB   14"!(DAV)ID=",041h,8,"D3"
   DB   12"(DDED)!=",041h,7,041h
   DB   13"#:(DED)!=",041h,7,041h
   DB   9,   ".E(D)!=",041h
   DB   11"#: E(D)!=("
   DB   12"!(DEA)TH=",041h,0Ah
   DB   19"!(DEBORAH)!=",041h,0Ah,"$",12h,1Dh,"X"
   DB   16"!(DECI)MAL=",041h,0Ah,"0",047h
   DB   13"!(DELI)=",041h,0Ah," ",7
   DB   17"!(DENISE)!=",041h,0Ah,038h,1,"0"
   DB   11"!(DE) #=",041h,7
   DB   13"!(DIA)L=",041h,0Eh,"äX"
   DB   14"!(DIA)NA=",041h,0Eh,"äL"
   DB   13"!(DIAR)=",041h,0Eh,"D£"
   DB   12":(DIER)=",041h,"1",1Ch
   DB   11"!(DIO)=",041h,1,0Eh
   DB   15"!(DIR)ECT=",041h,0Eh,"ä]"
   DB   11"!(DIS)=",041h,7,"0"
   DB   8,   "(DG)=",041h,"1"
   DB   8,   "(DJ)=",041h,"1"
   DB   12"!(DO)!=e½",16h,"ú"
   DB   17"(DOCTRI)N=",041h,"X)(",1Dh,047h
   DB   15"!(DO)ING!=e½",16h,"ú"
   DB   13"!(DOES)=ѽ",18h,"/"
   DB   12"!(DO)NE=ѽ",18h
   DB   16"!(DORO)THY!=",041h,12h,05Ch
   DB   13"!(DOUG)=",041h,18h,0E6h,"+"
   DB   12"(DOUGH)=",041h12h,"V"
   DB   11"!(DOW)=",041h,0Fh,17h
   DB   13"!(DR)!=",041h,0Eh,")(",1Ch
   DB   10"!(DR)=eq",05Ch
   DB   11"!(DU)A=",041h,"VV"
   DB   9,   "(DU)A=1",16h
   DB   10"#(DUR)=¦",1Ch
   DB   8,   "!(D)=ѽ"
   DB   8,   "(D)!=e+"
   DB   7,   "(DD)=e"
   DB   6,   "(D)=",041h
 
   
   DB   9,   "!(E)!=AA"
   DB   8,   "#:(E)!="
   DB   9,   "(E)MENT="
   DB   9,   "!:(E)!=",1
   DB   10":(EA)!=",1,1Ah
   DB   13"!(EARS)!=",1,05Ch,"/"
   DB   11"!(EAR)!=",1,05Ch
   DB   12"!(E)DITH!=",1
   DB   11"!(ED)!=JJ",041h
   DB   8,   "(ED)!=",041h
   DB   13"!(E)LAINE!=",1
   DB   19"!(ELEANOR)!=",0Ah," ",047h,038h,12h,05Ch
   DB   12"#:(ELY)!= ",1
   DB   9,   "(EA)D=JJ"
   DB   10"(EAR)N=",05Ch,05Ch
   DB   10"!(EAR) =",1Ch
   DB   9,   "(EA)RT=",0Eh
   DB   11"(EA)TURE=",1
   DB   10"(EAU)!=",11h,"c"
   DB   9,   "(EAU)=ä",16h
   DB   10"!(EA).=AA"
   DB   9,   "!(EA)=",1,"ü"
   DB   10"(EA):E!=",1
   DB   11"(EA):ED!=",1
   DB   10"(EA):EE=",1
   DB   11"(EA):ES!=",1
   DB   11"(EA):ING=",1
   DB   11"(EA).ON","=AA"
   DB   10"(EA) ON=",1
   DB   11"(EA) TH!=",0Ah
   DB   9,   "(EA):#=",0Ah
   DB   8,   "(EA)=-",1
   DB   9,   "(EE).=",1,"A"
   DB   7,   "(EE)=",1
   DB   9,   "(EF)UL=4"
   DB   8,   "(EH)#=",1
   DB   10"(EIGH)=",8,4
   DB   10"(EIN)=",8,"D",038h
   DB   7,   "(EI)=",1
   DB   12"!(ELA)B=",1," ",0Eh
   DB   11"!(ELE)=",0Ah," J"
   DB   19"!(ELIZA)BETH=",1," ",047h,"/X"
   DB   10"(EL).=",0Ah,"J`"
   DB   9,   "(EL) =",0Ah,"`"
   DB   13"!(EN)ERGY=",0Ah,038h
   DB   9,   "(ENE)=",1,038h
   DB   12"#:EM(E)NT=",0Ah
   DB   11"!:(EN)!=",0Ah,038h
   DB   9,   "(EN)!=xx"
   DB   10"(EN)S!=xx"
   DB   21"!(ENGLAND)!=",047h,038h,0E9h,0E6h," ",047h,038h,041h
   DB   7,   "(E)O=",1
   DB   18"!(EQUA)TION=",1,")c",8,"ä"
   DB   8,   "(E)QU=",2
   DB   11" (ERE)!=",2,1Ch
   DB   11"(ERE)LY=A",1Ch
   DB   11"(ERI)#=",1,1Dh,1
   DB   10"(ERI)=",0Ah1Dh,7
   DB   11"#:(ER)#=",0Ah,1Dh
   DB   12": (ERR)Y=",0Ah,1Dh
   DB   10"!(ERR)=",0Ah,05Ch
   DB   12"!(ER):# =",0Bh,1Dh
   DB   9,   "(ER)#=",0Ah,1Dh
   DB   9,   "(ER).=",1Ch,05Ch
   DB   7,   "(ER)=",1Ch
   DB   10"H(ES)!=",0Ah,"/"
   DB   10"(E)SIVE=",1
   DB   21"!(ESPECIAL)LY=",0Ah,"0",27h,0Ah,"2 "
   DB   9,   "#:(E)S!="
   DB   14"!(ETHEL)!=",0Ah,"6 "
   DB   8,   "L(EU)=",16h
   DB   8,   "R(EU)=",16h
   DB   15"!(EURO)PE=ä",16h,1Dh,"X"


NEXT PAGE
 

HOME  

  ROMHACK 2009