;ROM×²À+´Ð­Ú°À ¾²·Þ® ÌßÛ¸Þ×Ñ
;------ WORK ------
 ORG $8000
rnd:DS 2
MEM:DS 1   ;0=256 1=512 2=1M À²µ³
ROM:DS 1   ;¾Ú¸Ä ROM
SW0:DS 1   ;½²¯ÁÜ°¸
SW1:DS 1   ;½²¯ÁÜ°¸
SW0O:DS 1   ;½²¯ÁÜ°¸
SW1O:DS 1   ;½²¯ÁÜ°¸
;RLV:DS 1   ;0=LOAD 1=VERIFY
RAMADR:DS 3  ;RAM ADRESS
ROMADR:DS 3  ;ROM ADRESS
PRNN:DS 1  ;ÃÞ°À ÊÞ²Ä½³
PRXXXX:DS 2 ;±ÄÞÚ½
PRBANK:DS 1  ;1MÉÄ· 0=bank0 1=bank1 (INTEL HEX)
PRFF:DS 1   ;¿Þ¸¾² 00=Â³¼Þ®³ 01=END
PRCC:DS 1   ;Áª¯¸»Ñ
PRSUM:DS 1  ;»Ñ Á


PRBUF        ;ÌßØÝÀ ÊÞ¯Ì§
P09 EQU $09
P0D EQU $0D

 OFFSET $C000
 ORG $0000
 NOP:NOP:NOP
 DI:LD SP,$8800
 LD B,$00
WA0:DJNZ WA0
WA1:DJNZ WA1
WA2:DJNZ WA2
 LD A,$80:OUT ($0B),A
 LD A,11111000B:OUT ($08),A
 LD A,11111111B:OUT (P09),A
 LD A,11111111B:OUT ($0A),A
 LD A,$98:OUT ($0F),A
 LD A,$FF:OUT (P0D),A  ;LED ¹¼
 LD A,$0F:OUT ($0E),A  ;LED ¹¼
 LD A,$9B:OUT ($03),A:OUT ($07),A
;------  WORK RAM TEST --------
 LD BC,$8000
 LD HL,0
WRT00
 DB $54,$5D,$19,$19,$7D,$84,$67,$11,$81,0,$19,$7C
 LD (BC),A:INC BC
 LD A,B:CP $88:JP NZ,WRT00
;--- CHECK
 LD BC,$8000
 LD HL,0
WRT01
 DB $54,$5D,$19,$19,$7D,$84,$67,$11,$81,0,$19
 LD A,(BC):INC BC
 CP H:JP Z,WRT02
;---ERR
 LD A,$00:OUT ($0E),A
WRT03:JR WRT03
WRT02
 LD A,B:CP $88:JP NZ,WRT01
;------  RAM TEST --------
 LD A,$88:OUT ($03),A:LD A,$02:OUT ($02),A
 LD A,$92:OUT ($07),A
 LD HL,$0000
 LD D,0:EXX:LD HL,0:EXX
RTA00
 LD A,L:OUT ($00),A
 LD A,H:OUT ($01),A
 EXX
 DB $54,$5D,$19,$19,$7D,$84,$67,$11,$81,0,$19,$7C
 OUT ($06),A
 EXX
 OR A:JP NZ,BUGS0:INC A
BUGS0
 ADD A,L:LD L,A:LD A,H:ADC A,0:LD H,A
 LD A,11101000B:OUT ($08),A
 LD A,11111000B:OUT ($08),A
 JP NC,RTA00
RTAA0:LD A,D:OR A:JR NZ,RTA01
 INC D:LD A,$03:OUT ($02),A
 JR RTA00
RTA01
;----- CHECK
 LD A,$9B:OUT ($07),A
 LD A,$00:OUT ($02),A
 LD HL,$0000
 LD D,0:EXX:LD HL,0:EXX
RTC00
 LD A,L:OUT ($00),A
 LD A,H:OUT ($01),A
 EXX
 DB $54,$5D,$19,$19,$7D,$84,$67,$11,$81,0,$19
 IN A,($06):CP H:JR NZ,RTC02  ;:LD A,H
 EXX
 OR A:JP NZ,BUGS1:INC A
BUGS1
 ADD A,L:LD L,A:LD A,H:ADC A,0:LD H,A
 JP NC,RTC00
 LD A,D:OR A:JR NZ,RTC01
 INC D:LD A,$01:OUT ($02),A :JR RTC00
RTC01:LD A,2:LD (MEM),A:LD A,$B:LD (ROM),A:JR RTC06
;---- ERR ???
RTC02:EXX
 LD A,D:OR A:JR Z,RTC05
 LD A,1:LD (MEM),A:LD A,9:LD (ROM),A:JR RTC06
RTC05
 LD DE,$8000:XOR A:SBC HL,DE
 JR NC,RTC03
;----ERR !!!
RTC04:LD DE,$F000:CALL BZ:JR RTC04
RTC03
 LD A,0:LD (MEM),A:LD A,8:LD (ROM),A
RTC06
 CALL SER
;----------- RAM FF CLS ----------------
 CALL RAMFF
;------------ ºÉ ÌßÛ¸Þ×Ñ ¦ RAMÍ ------

 IN A,($0E):AND 10000000B:JP Z,PRRD2
 LD A,$9B:OUT ($07),A :OUT  ($03),A
 IN A,($08):OR 01110000B:AND 01111000B:OUT ($08),A
 LD A,11111111B:OUT (P09),A
 LD A,11111111B:OUT ($0A),A
 LD DE,$FFEF:CALL BZ
HANAL:IN A,($0E):AND 10000000B:JR NZ,HANAL
;IN A,($08):OR 00110000B:OUT ($08),A
;LD A,$9B:OUT ($07),A
 LD A,$88:OUT ($03),A:LD A,$02:OUT ($02),A
 LD A,$82:OUT ($07),A
 XOR A:LD (RAMADR),A:LD (RAMADR+1),A:LD (RAMADR+2),A
PRRM0
 LD HL,(RAMADR):LD DE,$1000:ADD HL,DE:LD A,(HL)
 OUT ($06),A
 LD A,(RAMADR):OUT ($00),A
 LD A,(RAMADR+1):OUT ($01),A
 LD A,(RAMADR+2):AND 1:OR $02:OUT ($02),A
 IN A,($08):AND 11101111B:OUT ($08),A :OR 00010000B:OUT ($08),A
 LD HL,(RAMADR):INC HL:LD (RAMADR),HL
 LD DE,PRGEND+$1000:XOR A:SBC HL,DE:JR NZ,PRRM0
PRRD2
;------------ MENU ----------
 XOR A:LD (SW0O),A:LD (SW1O),A
MENU





 LD A,$9B:OUT ($07),A :OUT  ($03),A
 IN A,($08):OR 01110000B:AND 01111000B:OUT ($08),A
 LD A,11111111B:OUT (P09),A
 LD A,11111111B:OUT ($0A),A

 LD DE,$5090:CALL BZ
 IN A,($0E):OR 00001010B:AND 11111011B:OUT ($0E),A
MENU1
 CALL KEYIN
;---- ROM SELECT
 LD A,(SW0):AND 00100000B:JR Z,KRS0
 LD A,(MEM)
 LD B,$A
 DEC A:JR NZ,KRS2:LD B,$B
KRS2
 DEC A:JR NZ,KRS3:LD B,$D
KRS3
 LD A,(ROM):INC A:CP B:JR NZ,KRS1:XOR A
KRS1:LD (ROM),A
 CALL SER
 LD DE,$2010:CALL BZ
 LD DE,$1010:CALL BZ
 LD DE,$5090:CALL BZ
 JR MENU1
KRS0
;----- ROM EMULETE
 LD A,(SW1):AND 01000000B:JP Z,RE00
 LD A,$8B:OUT ($07),A
 LD A,$9B:OUT ($03),A
 LD A,(ROM)
;---2716
 OR A:JR NZ,RT00
 LD A,00101000B:OUT ($04),A:LD A,11111100B:OUT (P09),A:JR RTEE
RT00
;---2532
 DEC A:JR NZ,RT01
 LD A,01001000B:OUT ($04),A:LD A,11111100B:OUT (P09),A:JR RTEE
RT01
;---2732 + A
 DEC A:JR Z,RT021
 DEC A:JR NZ,RT02
RT021
 LD A,00101100B:OUT ($04),A:LD A,11111100B:OUT (P09),A:JR RTEE
RT02
;---2764 + A
 DEC A:JR Z,RT031
 DEC A:JR NZ,RT03
RT031
 LD A,00101100B:OUT ($04),A:LD A,11111100B:OUT (P09),A:JR RTEE
RT03
;---27128 + A
 DEC A:JR Z,RT041
 DEC A:JR NZ,RT04
RT041
 LD A,00101110B:OUT ($04),A:LD A,11111100B:OUT (P09),A:JR RTEE
RT04
;---27256 + A
 DEC A:JR Z,RT05N
 DEC A:JR NZ,RT05
RT05N:LD A,00101111B:OUT ($04),A:LD A,11111100B:OUT (P09),A:JR RTEE
RT05
;---27512
 DEC A:JR NZ,RT06
 LD A,10101111B:OUT ($04),A:LD A,11111100B:OUT (P09),A:JR RTEE
RT06
;---27301
 DEC A:JR NZ,RT07
 LD A,10110111B:OUT ($04),A:LD A,11111110B:OUT (P09),A:JR RTEE
RT07
;---27010
 LD A,10101111B:OUT ($04),A:LD A,11111101B:OUT (P09),A  ;:JR RTEE
RTEE
 IN A,($08):AND 11011111B:OUT ($08),A
 IN A,($0E):OR 00000110B:AND 11110111B:OUT ($0E),A
 LD B,9
RE01
 LD DE,$5720:CALL BZ
 LD DE,$4130:CALL BZ
 DJNZ RE01
REKI0
 CALL KEYIN
 LD A,(SW1):AND 01000000B:JR Z,REKI0
 IN A,($08):OR 00100000B:OUT ($08),A
 LD A,$9B:OUT ($07),A
 LD B,6
RE01EN
 LD DE,$6730:CALL BZ
 LD DE,$8120:CALL BZ
 DJNZ RE01EN
 JP MENU
RE00
 ;---------------- ROM LOAD
 LD A,(SW0):AND 10000000B:JP Z,RRD2
 IN A,($0E):SET 2,A:RES 1,A:OUT ($0E),A
;IN A,($08):OR 00110000B:OUT ($08),A
;LD A,$9B:OUT ($07),A
 LD A,$88:OUT ($03),A:LD A,$02:OUT ($02),A
 LD A,$82:OUT ($07),A
 LD A,01100000B:OUT (P09),A
 LD A,10011101B:OUT ($0A),A     ;;;;;
 CALL OEH
 IN A,($08):OR 00000100B:OUT ($08),A
 CALL RTADR
 XOR A:LD (RAMADR),A:LD (RAMADR+1),A:LD (RAMADR+2),A
 CALL ROMADS
 LD DE,$1000:CALL WAIT
RRM0
 CALL ROMADS
 CALL OEL
 IN A,($05):OUT ($06),A
 CALL OEH
 LD A,(RAMADR):OUT ($00),A
 LD A,(RAMADR+1):OUT ($01),A
 LD A,(RAMADR+2):AND 1:OR $02:OUT ($02),A
 IN A,($08):AND 11101111B:OUT ($08),A :OR 00010000B:OUT ($08),A
 LD HL,RAMADR
 INC (HL):JR NZ,RRM1
 INC HL:INC (HL):JR NZ,RRM1
 INC HL:INC (HL)
RRM1
 LD HL,RAMADR
 LD A,(ROMADR):CP (HL):JR NZ,RRM0
 LD A,(ROMADR+1):INC HL:CP (HL):JR NZ,RRM0
 LD A,(ROMADR+2):INC HL:CP (HL):JR NZ,RRM0
 ;IN A,($08):AND 11111011B:OUT ($08),A
 JP MENU
RRD2
 ;---------------- ROM VERIFY
 LD A,(SW1):AND 00100000B:JP Z,RVD2
VERIFYY
 IN A,($0E):SET 2,A:RES 1,A:OUT ($0E),A
 ;IN A,($08):OR 00110000B:OUT ($08),A
 ;LD A,$9B:OUT ($07),A
 LD A,$88:OUT ($03),A:LD A,$02:OUT ($02),A
 LD A,$8B:OUT ($07),A
 LD A,01100000B:OUT (P09),A
 LD A,10011101B:OUT ($0A),A     ;;;;;  10011101
 CALL OEH
 IN A,($08):OR 00000100B:OUT ($08),A
 CALL RTADR
 XOR A:LD (RAMADR),A:LD (RAMADR+1),A:LD (RAMADR+2),A
 CALL ROMADS
  LD DE,$FFFF:CALL WAIT
RVM0
 CALL ROMADS
 LD A,(RAMADR):OUT ($00),A
 LD A,(RAMADR+1):OUT ($01),A
 LD A,(RAMADR+2):AND 1:OUT ($02),A
 CALL OEL   ;:LD DE,$1000:CALL WAIT   ;EEEEEE
 IN A,($05):LD H,A:IN A,($06):CP H:JP Z,RVEEE0
;--- ERROR!!!
;LD A,H:OUT (P0D),A
;CALL KEYBG
;IN A,($06):OUT (P0D),A
;CALL KEYBG
;LD A,(RAMADR):OUT (P0D),A
;CALL KEYBG
;LD A,(RAMADR+1):OUT (P0D),A
;CALL KEYBG
; JP RVEEE0


ERROR   ;´×° ¼®Ø
 LD A,$9B:OUT ($07),A :OUT  ($03),A
 IN A,($08):OR 01110000B:AND 01111000B:OUT ($08),A
 LD A,11111111B:OUT (P09),A
 LD A,11111111B:OUT ($0A),A
 LD B,7
RVEEE1
 LD DE,$2545:CALL BZ
 LD DE,$8110:CALL BZ
 DJNZ RVEEE1
RVEEE2
 IN A,($0E):SET 2,A:OUT ($0E),A
 LD DE,$2300:CALL WAIT
 CALL KEYIN:CALL KEYS:JR NZ,RVEEE3
 IN A,($0E):RES 2,A:OUT ($0E),A
 LD DE,$2300:CALL WAIT
 CALL KEYIN:CALL KEYS:JR Z,RVEEE2
RVEEE3
 JP MENU
RVEEE0
 LD A,(RAMADR+2):AND 1:OR $2:OUT ($02),A
 CALL OEH
 LD HL,RAMADR
 INC (HL):JR NZ,RVM1
 INC HL:INC (HL):JR NZ,RVM1
 INC HL:INC (HL)
RVM1
 LD HL,RAMADR
 LD A,(ROMADR):CP (HL):JP NZ,RVM0
 LD A,(ROMADR+1):INC HL:CP (HL):JP NZ,RVM0
 LD A,(ROMADR+2):INC HL:CP (HL):JP NZ,RVM0
 ;IN A,($08):AND 11111011B:OUT ($08),A
 JP MENU
RVD2
 ;---------------- ROM WRITE
 LD A,(SW0):AND 01000000B:JP Z,RWD2
 IN A,($0E):SET 2,A:RES 1,A:OUT ($0E),A
 ;IN A,($08):OR 00110000B:OUT ($08),A
 ;LD A,$9B:OUT ($07),A
 LD A,$88:OUT ($03),A:LD A,$02:OUT ($02),A
 LD A,(ROM)
 OR A:JR NZ,RWW0
 IN A,($08):RES 0,A:RES 1,A:OUT ($08),A   ;25V
 LD A,11101000B:OUT (P09),A
 LD A,10100111B:OUT ($0A),A
 JP RWWEE
RWW0
 CP 1:JR NZ,RWW1   ;2532
 IN A,($08):RES 0,A:RES 1,A:OUT ($08),A   ;25V   ??????????????
 LD A,11100000B:OUT (P09),A
 LD A,10101111B:OUT ($0A),A
 JP RWWEE
RWW1
 CP 2:JR NZ,RWW2   ;2732
 IN A,($08):RES 0,A:RES 1,A:OUT ($08),A   ;25V
 LD A,11101000B:OUT (P09),A
 LD A,10111011B:OUT ($0A),A
 JP RWWEE
RWW2
 CP 3:JR NZ,RWW3   ;2732A
 IN A,($08):SET 0,A:RES 1,A:OUT ($08),A   ;21V
 LD A,11101000B:OUT (P09),A
 LD A,10111011B:OUT ($0A),A
 JP RWWEE
RWW3
 CP 6:JR Z,RWW41   ;27128
 CP 4:JR NZ,RWW4   ;2764
RWW41:IN A,($08):SET 0,A:RES 1,A:OUT ($08),A   ;21V
 LD A,11100000B:OUT (P09),A
 LD A,11110110B:OUT ($0A),A
 JP RWWEE
RWW4
 CP 7:JR Z,RWW51   ;27128A
 CP 5:JR NZ,RWW5   ;2764A
RWW51:IN A,($08):RES 0,A:SET 1,A:OUT ($08),A   ;12.5V
 LD A,11100000B:OUT (P09),A
 LD A,11110110B:OUT ($0A),A
 JP RWWEE
RWW5

 CP 8:JR NZ,RWW6N  ;27256
 IN A,($08):SET 0,A:RES 1,A:OUT ($08),A   ;21V
 LD A,11001000B:OUT (P09),A
 LD A,11110110B:OUT ($0A),A
 JP RWWEE
RWW6N
 CP 9:JR NZ,RWW6   ;27256A
 IN A,($08):RES 0,A:SET 1,A:OUT ($08),A   ;12.5V
 LD A,11001000B:OUT (P09),A
 LD A,11110110B:OUT ($0A),A
 JP RWWEE
RWW6
 CP $A:JR NZ,RWW7   ;27512
 IN A,($08):RES 0,A:SET 1,A:OUT ($08),A   ;12.5V
 LD A,11001000B:OUT (P09),A
 LD A,11111011B:OUT ($0A),A
 JP RWWEE
RWW7
 CP $B:JR NZ,RWW8   ;27301
 IN A,($08):RES 0,A:SET 1,A:OUT ($08),A   ;12.5V
 LD A,11000000B:OUT (P09),A
 LD A,01111111B:OUT ($0A),A
 JP RWWEE
RWW8
                   ;27010
 IN A,($08):RES 0,A:SET 1,A:OUT ($08),A   ;12.5V
 LD A,01000000B:OUT (P09),A
 LD A,01110111B:OUT ($0A),A
RWWEE
 LD A,$89:OUT ($07),A  :LD A,$FF:OUT ($05),A
 LD DE,$1000:CALL WAIT
 IN A,($08):OR 00000100B:OUT ($08),A

 ;LD DE,$FFFF:CALL BZ
 ;LD DE,$FFFF:CALL BZ
 CALL RTADR
 XOR A:LD (RAMADR),A:LD (RAMADR+1),A:LD (RAMADR+2),A
 CALL ROMADS
 LD DE,$0000:CALL WAIT
RWM0
 CALL ROMADS
 LD A,(RAMADR):OUT ($00),A
 LD A,(RAMADR+1):OUT ($01),A
 LD A,(RAMADR+2):AND 1:       OUT ($02),A
   LD DE,$10:CALL WAIT

 IN A,($06):OUT ($05),A:INC A:LD A,$2:OUT ($02),A:JP Z,RPLSEEN
 ;LD DE,$FFFF:CALL BZ
 ;LD DE,$5555:CALL BZ
  LD DE,$100:CALL WAIT



;------ WRITE PULS
 LD A,(ROM)
 OR A:JR NZ,RPLS0
RPLS1
 IN A,(P09):AND 11110111B:OUT (P09),A
 CALL M50
 IN A,(P09):OR  00001000B:OUT (P09),A
 JP RPLSEE
RPLS0
 CP 2:JR Z,RPLS1
 CP 3:JR Z,RPLS1
 CP 8:JR Z,RPLS1
 CP 9:JR Z,RPLS1
 CP $A:JR Z,RPLS1
 CP 1:JR NZ,RPLS2
 IN A,($0A):AND 11110111B:OUT ($0A),A
 CALL M50
 IN A,($0A):OR  00001000B:OUT ($0A),A
 JP RPLSEE
RPLS2
 CP $B:JR C,RPLS3
 IN A,(P09):AND 10111111B:OUT (P09),A
 CALL M50
 IN A,(P09):OR  01000000B:OUT (P09),A
 JP RPLSEE
RPLS3
 IN A,(P09):AND 11011111B:OUT (P09),A
 CALL M50
 IN A,(P09):OR  00100000B:OUT (P09),A
RPLSEE  :LD A,$FF:OUT ($05),A    ;:LD DE,$2800:CALL WAIT
RPLSEEN
 LD HL,RAMADR
 INC (HL):JR NZ,RWM1
 INC HL:INC (HL):JR NZ,RWM1
 INC HL:INC (HL)
RWM1
 LD HL,RAMADR
 LD A,(ROMADR):CP (HL):JP NZ,RWM0
 LD A,(ROMADR+1):INC HL:CP (HL):JP NZ,RWM0
 LD A,(ROMADR+2):INC HL:CP (HL):JP NZ,RWM0
 LD A,10111111B:OUT ($0A),A
 LD A,11111111B:OUT (P09),A:LD DE,$1000:CALL WAIT
 LD A,11111111B:OUT ($0A),A
 LD A,$9B:OUT ($07),A :OUT  ($03),A
 IN A,($08):OR 01110000B:AND 01111000B:OUT ($08),A
 JP VERIFYY
RWD2
;---------------  PRINTER
 LD A,(SW0):AND 00010000B:JP Z,PRINT0
;IN A,($08):OR 00110000B:OUT ($08),A
;LD A,$9B:OUT ($07),A
 LD A,$88:OUT ($03),A:LD A,$02:OUT ($02),A
 LD A,$92:OUT ($07),A
 CALL RTADR
 XOR A:LD (RAMADR),A:LD (RAMADR+1),A:LD (RAMADR+2),A :LD (PRBANK),A
 IN A,($0E):SET 2,A:RES 1,A:OUT ($0E),A
 LD DE,$8432:CALL BZ
 LD DE,$9113:CALL BZ:CALL KEYHW
 IN A,($02):RES 3,A:OUT ($02),A:SET 3,A:OUT ($02),A
 IN A,($08):OR 01000000B:LD B,A:AND 10111111B:LD C,A:OUT ($08),A
PRINT1
 IN A,($0E):AND 00010000B:JP NZ,PRINT2
 IN A,($02):AND 00010000B:JR NZ,PRINT1  :LD A,B:OUT ($08),A
;---- INTEL HEX
     LD HL,PRBUF :LD DE,$100D:JR PR04
PR07:LD HL,PRBUF :LD DE,$100D
 IN A,($02):RES 3,A:OUT ($02),A:SET 3,A:OUT ($02),A
 IN A,($08):OR 01000000B:LD B,A:AND 10111111B:LD C,A  ;:OUT ($08),A
PRRRR
 LD A,C:OUT ($08),A
PR00
 IN A,($02):AND D        :JP NZ,PR00
PR04:LD A,B:OUT ($08),A:IN A,($0C):LD (HL),A:CP E :JR Z,PR02:INC HL
 IN A,($0E):AND 00010000B:JP NZ,ESC
PR01
 IN A,($02):RES 3,A:OUT ($02),A:SET 3,A:OUT ($02),A
 IN A,($02):AND D        :JP Z,PR01
 JP PRRRR    ;PR00
PR02
 LD A,B:OUT ($08),A   ;IN A,($08):OR  01000000B:OUT ($08),A
 ;;; PUSH DE:LD DE,$3040:CALL BZ:LD DE,$6030:CALL BZ:POP DE   ;;;;;;;
PR03
 IN A,($02):RES 3,A:OUT ($02),A:SET 3,A:OUT ($02),A
 IN A,($02):AND 00010000B:JR Z,PR03
 LD HL,PRBUF
PR05
 LD A,(HL):INC HL
 CP ":":JR Z,PR06
 CP $D:JR NZ,PR05
 JR PR07
PR06:XOR A:LD (PRSUM),A
 CALL HL2:JP C,PRERR :LD (PRNN),A
 CALL HL4:JP C,PRERR :LD (PRXXXX),BC
 CALL HL2:JP C,PRERR :LD (PRFF),A
 LD A,(PRNN):OR A:JR Z,PPR1
PPR0
 PUSH AF
 CALL HL2:JR NC,PPR2:POP AF:JP PRERR
PPR2
 OUT ($06),A
 LD A,(PRXXXX+0):OUT ($00),A
 LD A,(PRXXXX+1):OUT ($01),A
 LD A,(PRBANK):OR $02:OUT ($02),A
 IN A,($08):AND 11101111B:OUT ($08),A:OR 00010000B:OUT ($08),A
 LD BC,(PRXXXX):INC BC:LD (PRXXXX),BC
 POP AF:DEC A:JP NZ,PPR0
PPR1
 CALL HL2:JP C,PRERR: LD (PRCC),A
 LD A,(PRSUM):OR A:JP NZ,PRERR
 LD A,(PRFF):DEC A:JP Z,SUUU
 JP PR07
;-------- ÌÞ¼Þ ¼­³Ø®³
SUUU
 IN A,($08):RES 6,A:OUT ($08),A
 LD DE,$FFFF:CALL WAIT
 LD DE,$FFFF:CALL WAIT
 LD DE,$FFFF:CALL WAIT
 LD DE,$FFFF:CALL WAIT
 LD DE,$FFFF:CALL WAIT
 JP MENU
; --------- ESCEPE
ESC:CALL KEYIN
 LD DE,$2554:CALL BZ
 LD DE,$1145:CALL BZ
 LD DE,$0932:CALL BZ:CALL KEYHW
 JP MENU
;--------- INTEL HEX ERROR!!!
PRERR
 JP ERROR
;----------- BINARY
PRINT2
 LD DE,$5432:CALL BZ
 LD DE,$A113:CALL BZ:CALL KEYHW
 IN A,($02):RES 3,A:OUT ($02),A:SET 3,A:OUT ($02),A
PRINT3
 IN A,($0E):AND 00010000B:JP NZ,ESC
 LD A,(MEM):CP $2:JR NZ,PRINT41
 IN A,($0E):AND 00010000B:JP NZ,PRINT4
PRINT41:IN A,($02):AND 00010000B:JR NZ,PRINT3
 JR BPR04
BPR00S:IN A,($08):AND 10111111B:OUT ($08),A
BPR00:IN A,($0E):AND 00010000B:JP NZ,ESC
 IN A,($02):AND 00010000B:JR NZ,BPR00
BPR04:IN A,($0C):OUT ($06),A
  IN A,($08):OR 01000000B:OUT ($08),A
 LD A,(RAMADR):OUT ($00),A
 LD A,(RAMADR+1):OUT ($01),A
 LD A,(PRBANK):OR $02:OUT ($02),A
 IN A,($08):AND 11101111B:OUT ($08),A :OR 00010000B:OUT ($08),A
 LD HL,(RAMADR):INC HL:LD (RAMADR),HL
 LD DE,(ROMADR):XOR A:SBC HL,DE :JP Z,SUUU
BPR01
 IN A,($02):RES 3,A:OUT ($02),A:SET 3,A:OUT ($02),A
 IN A,($02):AND 00010000B:JR Z,BPR01
 JP BPR00S
;--------- INTEL HEX BANK1
PRINT4:LD A,1:LD (PRBANK),A
 LD DE,$7454:CALL BZ
 LD DE,$2222:CALL BZ:CALL KEYHW
 JP PR07
PRINT0
;----------- ERASE CHECK
 LD A,(SW1):AND 10000000B:JR Z,RAFC00
 IN A,($0E):SET 2,A:RES 1,A:OUT ($0E),A
 ;IN A,($08):OR 00110000B:OUT ($08),A
 ;LD A,$9B:OUT ($07),A
 LD A,$88:OUT ($03),A:LD A,$00:OUT ($02),A
 LD A,$8B:OUT ($07),A
 LD A,01100000B:OUT (P09),A
 LD A,10011101B:OUT ($0A),A
 CALL OEH
 IN A,($08):OR 00000100B:OUT ($08),A
 LD DE,$1000:CALL WAIT
 CALL RTADR
 XOR A:LD (RAMADR),A:LD (RAMADR+1),A:LD (RAMADR+2),A
ERVM0
 CALL ROMADS
 CALL OEL
 IN A,($05):INC A:JP Z,ERVEEE0
;--- ERROR!!!
 JP ERROR   ;´×° ¼®Ø
ERVEEE0
 CALL OEH
 LD HL,RAMADR
 INC (HL):JR NZ,ERVM1
 INC HL:INC (HL):JR NZ,ERVM1
 INC HL:INC (HL)
ERVM1
 LD HL,RAMADR
 LD A,(ROMADR):CP (HL):JP NZ,ERVM0
 LD A,(ROMADR+1):INC HL:CP (HL):JP NZ,ERVM0
 LD A,(ROMADR+2):INC HL:CP (HL):JP NZ,ERVM0
 ;IN A,($08):AND 11111011B:OUT ($08),A
 JP MENU
;IN A,($0E):SET 2,A:RES 1,A:OUT ($0E),A
;CALL RAMFF:JP MENU
RAFC00
 JP MENU1
;------ 2ÊÞ²Ä --> A
HL2:CALL SPCUT
 CALL SSUB:RET C
 RLCA:RLCA:RLCA:RLCA:LD B,A
 CALL SSUB:RET C
 OR B:LD B,A
 PUSH AF :LD A,(PRSUM):ADD A,B:LD (PRSUM),A:POP AF
 RET
;------ 4ÊÞ²Ä --> BC
HL4:CALL SPCUT
 CALL SSUB:RET C
 RLCA:RLCA:RLCA:RLCA:LD B,A
 CALL SSUB:RET C
 OR B:LD B,A
 LD A,(PRSUM):ADD A,B:LD (PRSUM),A
 CALL SSUB:RET C
 RLCA:RLCA:RLCA:RLCA:LD C,A
 CALL SSUB:RET C
 OR C:LD C,A
 PUSH AF :LD A,(PRSUM):ADD A,C:LD (PRSUM),A:POP AF
 RET
;------ ½Íß°½ ¶¯Ä
SPCUT
 LD A,(HL):CP " ":RET NZ
 INC HL:JP SPCUT
;------------
SSUB:LD A,(HL):INC HL
 CP "0":JR C,HL2ERR
 CP "G":JR C,HL2E0
 CP "a":JR C,HL2ERR
 CP "g":JR NC,HL2ERR
 SUB "a"-$A:OR A:RET
HL2E0
 CP "9"+1:JR NC,HL2E1
 SUB "0":OR A:RET
HL2E1
 CP "A":JR C,HL2ERR
 SUB "A"-$A:OR A:RET
HL2ERR
 SCF:RET
;----- ROMÀ²ÌßÆÖ¯Ã ROMADR SET
RTADR:XOR A:LD (ROMADR),A:LD (ROMADR+1),A:LD (ROMADR+2),A
 LD A,(ROM):OR A:JR NZ,RTT0:LD A,$08:LD (ROMADR+1),A:RET
RTT0
 CP 4:JR NC,RTT1:LD A,$10:LD (ROMADR+1),A:RET
RTT1
 CP 6:JR NC,RTT2:LD A,$20:LD (ROMADR+1),A:RET
RTT2
 CP 8:JR NC,RTT3:LD A,$40:LD (ROMADR+1),A:RET
RTT3
 CP $A:JR NC,RTT4:LD A,$80:LD (ROMADR+1),A:RET
RTT4
 CP $B:JR NC,RTT5:LD A,$01:LD (ROMADR+2),A:RET
RTT5
 LD A,$02:LD (ROMADR+2),A:RET

;------- OE ¦ H Æ
OEH
 LD A,(ROM):CP $B:JR Z,OEH301
 IN A,($0A):RES 3,A:OUT ($0A),A:RET
OEH301
 IN A,(P09):SET 7,A:OUT (P09),A:RET
;------- OE ¦ L Æ
OEL
 LD A,(ROM):CP $B:JR Z,OEL301
 IN A,($0A):SET 3,A:OUT ($0A),A  ;:RET
       PUSH DE:LD DE,$100:CALL WAIT:POP DE :RET
OEL301
 IN A,(P09):RES 7,A:OUT (P09),A  ;:RET
       PUSH DE:LD DE,$100:CALL WAIT:POP DE :RET

;-------  ROM ±ÄÞÚ½ Æ Ö¯Ã WAIT
;ROMAW
;LD A,(RAMADR+0):OR A:JR Z,ROMAW1
;LD A,(RAMADR+1):AND 000A:JR Z,ROMAW1

;----- RAMADR --> ROM±ÄÞÚ½¼­ÂØ®¸
ROMADS
 LD HL,(RAMADR):LD A,(RAMADR+2):LD D,A
;----- ROM ±ÄÞÚ½ ¼­ÂØ®¸Ù°ÁÝ  HL=±ÄÞÚ½ D=»²¼Þ®³²
ROMAD:
 PUSH HL:CALL RRRR:POP HL
         PUSH DE:LD DE,$20:CALL WAIT:POP DE
 ;---- A13ÍÝº³ Ä· WAIT    EEEEEEEEEEEEEEEE
 LD A,L:OR A:JP NZ,NRAH0
 LD A,H:AND 00000111B:JR NZ,NRAH0
 PUSH DE:LD DE,$1000:CALL WAIT:POP DE
NRAH0 :RET
RRRR:LD A,L:OUT ($04),A
 LD A,(ROM):OR A:JR NZ,ROMAD12
 LD A,H:AND 00010111B:LD E,A:IN A,(P09):AND 11101000B:OR E:OUT (P09),A
 RET
ROMAD12
 LD A,(ROM):CP 1:JR NZ,ROMAD1
 LD A,H:OUT (P09),A
 RET
ROMAD1
 CP 6:JR NC,ROMAD2   ;2732 64
 LD A,H:AND 00010111B:LD E,A:IN A,(P09):AND 11101000B:OR E:OUT (P09),A
 IN A,($0A):OR 00110000B:BIT 3,H:JR Z,ROBB0:AND 11011111B
ROBB0:OUT ($0A),A :RET
ROMAD2
 CP 8:JR NC,ROMAD3   ;27128
 LD A,H:AND 00010111B:LD E,A:IN A,(P09):AND 11101000B:OR E:OUT (P09),A
 IN A,($0A):OR 01110000B
 BIT 5,H:JR Z,ROBB2:AND 10111111B
ROBB2
 BIT 3,H:JR Z,ROBB1:AND 11011111B
ROBB1:OUT ($0A),A :RET
ROMAD3
 CP $A:JR NC,ROMAD4   ;27256
 LD A,H:AND 00010111B:LD E,A:IN A,(P09):AND 11001000B:OR E
 BIT 6,H:JR Z,ROBB3:OR  00100000B
ROBB3:OUT (P09),A
 IN A,($0A):OR 01110000B
 BIT 5,H:JR Z,ROBB4:AND 10111111B
ROBB4
 BIT 3,H:JR Z,ROBB5:AND 11011111B
ROBB5:OUT ($0A),A :RET
ROMAD4
 CP $B:JR NC,ROMAD5   ;27512
 LD A,H:AND 00010111B:LD E,A:IN A,(P09):AND 11001000B:OR E
 BIT 6,H:JR Z,ROBB6:OR  00100000B
ROBB6:OUT (P09),A
 IN A,($0A):OR 01110011B
 BIT 7,H:JR Z,ROBB9:AND 11111101B
ROBB9
 BIT 5,H:JR Z,ROBB7:AND 10111111B
ROBB7
 BIT 3,H:JR Z,ROBB8:AND 11011111B
ROBB8:OUT ($0A),A :RET
ROMAD5
 CP $C:JR NC,ROMAD6   ;27301
 LD A,H:AND 00010111B:LD E,A:IN A,(P09):AND 11001000B:OR E
 BIT 6,H:JR Z,ROBBA:OR  00100000B
ROBBA:OUT (P09),A
 IN A,($0A):OR 01111111B
 BIT 0,D:JR Z,ROBBE:AND 11110111B
ROBBE
 BIT 7,H:JR Z,ROBBB:AND 11111101B
ROBBB
 BIT 5,H:JR Z,ROBBC:AND 10111111B
ROBBC
 BIT 3,H:JR Z,ROBBD:AND 11011111B
ROBBD:OUT ($0A),A:RET
ROMAD6
                      ;27010
 LD A,H:AND 00010111B:LD E,A:IN A,(P09):AND 01001000B:OR E
 BIT 0,D:JR Z,ROBB1E:OR  10000000B
ROBB1E
 BIT 6,H:JR Z,ROBB1A:OR  00100000B
ROBB1A:OUT (P09),A
 IN A,($0A):OR 01110011B
 BIT 7,H:JR Z,ROBB1B:AND 11111101B
ROBB1B
 BIT 5,H:JR Z,ROBB1C:AND 10111111B
ROBB1C
 BIT 3,H:JR Z,ROBB1D:AND 11011111B
ROBB1D:OUT ($0A),A
 RET
;------ ½²¯Á ÊÅ½ÏÃÞ WAIT
KEYHW
 IN A,($0E):AND 11110000B:JR NZ,KEYHW
 IN A,($02):AND 11100000B:JR NZ,KEYHW
 RET

;-------
KEYBG
 PUSH AF:PUSH HL:PUSH BC:PUSH DE:LD DE,$FFFF:CALL BZ
KEYBG1:CALL KEYIN
 CALL KEYS
 JR Z,KEYBG1
 POP DE:POP BC:POP HL:POP AF:RET

;------ ÅÆ¶ ½²¯Á µ¼ÃÙ ?
KEYS
 LD A,(SW0):AND 11110000B:RET NZ
 LD A,(SW1):AND 11100000B:RET     ;;;;;;;;;;
;------ ½²¯Á Æ­³Ø®¸ Ù°ÁÝ
KEYIN
 IN A,($0E):LD B,A
 LD HL,SW0O:XOR (HL):AND B:LD (SW0),A:LD (HL),B
 IN A,($02):LD B,A
 LD HL,SW1O:XOR (HL):AND B:LD (SW1),A:LD (HL),B
 RET
;------- ¾Ú¸Ä ROM ºÝ¿°Ù DISP
SER
 IN A,($0E):SET 0,A:OUT ($0E),A
 IN A,($08):SET 3,A:OUT ($08),A
 LD A,$FF:OUT (P0D),A
 LD A,(ROM)
 OR A:JR NZ,SER1:LD A,11111110B:OUT (P0D),A:RET
SER1
 DEC A:JR NZ,SER2:LD A,11111101B:OUT (P0D),A:RET
SER2
 DEC A:JR NZ,SER3:LD A,11111011B:OUT (P0D),A:RET
SER3
 DEC A:JR NZ,SER21:LD A,11111011B:OUT (P0D),A
 IN A,($08):RES 3,A:OUT ($08),A:RET
SER21
 DEC A:JR NZ,SER4:LD A,11110111B:OUT (P0D),A:RET
SER4
 DEC A:JR NZ,SER22:LD A,11110111B:OUT (P0D),A
 IN A,($08):RES 3,A:OUT ($08),A:RET
SER22
 DEC A:JR NZ,SER5:LD A,11101111B:OUT (P0D),A:RET
SER5
 DEC A:JR NZ,SER23:LD A,11101111B:OUT (P0D),A
 IN A,($08):RES 3,A:OUT ($08),A:RET
SER23
 DEC A:JR NZ,SER6:LD A,11011111B:OUT (P0D),A:RET
SER6
 DEC A:JR NZ,SER24:LD A,11011111B:OUT (P0D),A
 IN A,($08):RES 3,A:OUT ($08),A:RET
SER24: DEC A:JR NZ,SER7:LD A,10111111B:OUT (P0D),A:RET
SER7
 DEC A:JR NZ,SER8:LD A,01111111B:OUT (P0D),A:RET
SER8
 IN A,($0E):RES 0,A:OUT ($0E),A:RET

;------- ÌÞ»Þ° --D=µÝÃ² E=µÄÉÅ¶Þ»
BZ
 PUSH AF:PUSH BC
BZ3
 IN A,($08):AND 01111111B:OUT ($08),A
 LD B,D
BZ1:NOP:NOP:NOP:DJNZ BZ1
 IN A,($08):OR  10000000B:OUT ($08),A
 LD B,D
BZ2:NOP:NOP:NOP:DJNZ BZ2
 DEC E:JP NZ,BZ3
 POP BC:POP AF
 RET
;-------- WAIT   DE=Å¶Þ»
WAIT:PUSH DE:PUSH AF
WAIT1:DEC DE
 LD A,D:OR E:JR NZ,WAIT1
 POP AF:POP DE:RET
;-------- 50ms WAIT
M50
 PUSH AF:PUSH BC:LD BC,$2000  ;   1480
M501:DEC BC:LD A,C:OR B:JR NZ,M501:POP BC:POP AF:RET
;--------- RAM FF ALL CLS
RAMFF
 IN A,($08):OR 00110000B:OUT ($08),A
 LD A,$9B:OUT ($07),A
 LD A,$88:OUT ($03),A:LD A,$02:OUT ($02),A
 LD A,$92:OUT ($07),A
 LD HL,$0000
 LD D,0
 LD A,$FF:OUT ($06),A
 LD A,11101000B:OUT ($08),A
 LD C,$00
RFFC1
 LD A,H:OUT ($01),A
 LD B,$40
RFFC0
 LD A,11111000B:OUT ($08),A:OUT (C),L:INC L:LD A,11101000B:OUT ($08),A
 LD A,11111000B:OUT ($08),A:OUT (C),L:INC L:LD A,11101000B:OUT ($08),A
 LD A,11111000B:OUT ($08),A:OUT (C),L:INC L:LD A,11101000B:OUT ($08),A
 LD A,11111000B:OUT ($08),A:OUT (C),L:INC L:LD A,11101000B:OUT ($08),A
;OUT (C),L:INC L
 DJNZ RFFC0
 INC H:JR NZ,RFFC1
 LD A,D:OR A:JR NZ,RTF01
 INC D:LD A,$03:OUT ($02),A :LD A,(MEM):CP 2:JR Z,RFFC1
RTF01
 LD A,11111000B:OUT ($08),A
 RET





PRGEND





d¢ÍG¢þ`Ò( w