Skip to content

Instantly share code, notes, and snippets.

Created Feb 10, 2017
Embed
What would you like to do?
10 SCREEN 0
10 SCREEN 0
20 WIDTH 40
30 BLOAD"PROGRAM.BIN",R
{"asm":{"filename":"program.bin","build":"bin"},"basic":{}}
CHPUT: equ 0x00A2
INITXT: equ 0X006C
LDIRVM: equ 0X005C
LDIRMV: equ 0X0059
CHGET: equ 0X009F
CHSNS: equ 0X009C
ERAFNK: equ 0X00CC
POSIT: equ 0X00C6
; the address of our program
org 0xC000
TXTSUBMENU: db ' MSX1 Games',0,' MSX2 Games',0,' MSX Turbo-R Games',1,' Documents',1,' Settings',0,' Default Settings',1,' Security',1,' Help ',1,' Run',0FFH
TXTORDER: db 1,1,1,1,1,1
start:
call INITXT
call ERAFNK
ld hl,TXTMENU
ld d,10
ld e,10
ld b,1
ld c,20
call MAKEMENU
ret
; --------------------- begin | main procedure
MAKEMENU: ld (MMREGHL),hl
call MMCALCADDR
ld (MMREGDE),de
ld (MMREGBC),bc
ld hl,TXTORDER
ld (ADDRORDER),hl
MMLOOP1: call MAKETXT
ld hl,SUBVALS
ld (ADDRSUB),hl
ld a,(MMREGBC)
ld c,a
ld de,(MMREGDE)
ld hl,(MMREGHL)
call INITMENU
MMLOOP2: call CHSNS
jr z,MMLOOP2
call CHGET
cp 30
jp z,MUP
cp 31
jp z,MDOWN
cp 29
jr z,MLEFT
cp 28
jr z,MRIGHT
cp 13
jr z,MENTER
cp 27
ret z
jr MMLOOP2
MENTER: ld a,(IMPOSIT)
ld b,a
ld hl,(ADDRORDER)
call MRGETHL
ld a,(hl)
ld c,a
push bc
ld hl,TXTOUT
ld de,807
ld bc,26
call LDIRVM
pop bc
push bc
ld a,b
ld hl,815
call PRINTBYTE
ld a,c
ld hl,831
call PRINTBYTE
pop bc
ret
MLEFT: ld hl,(ADDRORDER)
call MRGETHL
ld a,(hl)
cp 1
jr nz,MLNORM
push hl
ld hl,(ADDRSUB)
call MRGETHL
ld a,(hl)
pop hl
jr MLJUMP
MLNORM: dec a
MLJUMP: ld (hl),a
ld a,(IMPOSIT)
ld b,a
jp MMLOOP1
MRIGHT: ld hl,(ADDRORDER)
call MRGETHL
ld (MRREGHL),hl
ld a,(hl)
ld c,a
ld hl,(ADDRSUB)
call MRGETHL
ld a,(hl)
cp c
jr nz,MRNORM
ld a,1
jr MRJUMP
MRNORM: ld a,c
inc a
MRJUMP: ld hl,(MRREGHL)
ld (hl),a
ld a,(IMPOSIT)
ld b,a
jp MMLOOP1
MUP: ld a,(IMPOSIT)
cp 1
jr z,MCIMAPOS1
dec a
ld b,a
call IMCLEARBAR
jp MMLOOP1
MCIMAPOS1: ld a,(IMCOUNTER)
ld b,a
call IMCLEARBAR
jp MMLOOP1
MDOWN: ld a,(IMPOSIT)
ld b,a
ld a,(IMCOUNTER)
cp b
jr z,MBAIXOPOSU
ld a,b
inc a
ld b,a
call IMCLEARBAR
jp MMLOOP1
MBAIXOPOSU: ld a,1
ld b,a
call IMCLEARBAR
jp MMLOOP1
MRREGHL: dw 0
; --------------------- end | main procedure
; --------------------- begin | procedure to calculate VRAM address with coordinates
MMCALCADDR: push bc
push de
ld d,0
ld bc,40
call MULTI
pop de
ld e,d
ld d,0
add hl,de
push hl
pop de
pop bc
ret
; --------------------- end | procedure to calculate VRAM address with coordinates
; --------------------- begin | auxiliary procedures
MRGETHL: ld a,(IMPOSIT)
ld de,0
ld e,a
add hl,de
dec hl
ret
MTBLOCK: push hl
push bc
ld hl,(MTREGTM)
ld a,(MTCOUNTER)
ld c,a
ld b,0
add hl,bc
ld (MTREGBC),bc
push hl
ld hl,(MTREGHL2)
ld de,(MTREGTM)
ldir
pop hl
ld (MTREGTM),hl
pop bc
pop hl
ret
MTBLOCK2: ld a,(MTCOUNTERC)
ld b,a
ld de,(MTREGTO)
ld a,(de)
ret
MTHUMBLOCK: call MTBLOCK2
cp b
call z,MTBLOCK
push hl
ld a,1
ld (MTCOUNTERC),a
ld hl,(MTREGTO)
inc hl
ld (MTREGTO),hl
pop hl
inc hl
ret
MTINCHL2: ld hl,(MTREGHL)
inc hl
ld (MTREGHL2),hl
xor a
ld (MTCOUNTER),a
ret
MTINCVALS: ld hl,(ADDRSUB)
ld a,(MTCOUNTERC)
ld (hl),a
inc hl
ld (ADDRSUB),hl
ret
; --------------------- end | auxiliary procedures
; --------------------- begin | procedure to created correct TXT for procedure INITMENU
MAKETXT: push hl
push de
push bc
ld hl,SUBVALS
ld (ADDRSUB),hl
ld hl,TXTORDER
ld (MTREGTO),hl
ld hl,TXTMENU
ld (MTREGTM),hl
ld a,1
ld (MTCOUNTERC),a
xor a
ld (MTCOUNTER),a
ld hl,TXTSUBMENU
ld (MTREGHL),hl
ld (MTREGHL2),hl
MTLOOP: ld hl,(MTREGHL)
ld a,(hl)
and a
jp z,MTZERO
cp 1
jp z,MTHUM
cp 0ffh
jp z,MTFF
ld a,(MTCOUNTER)
inc a
ld (MTCOUNTER),a
MTBACK: ld hl,(MTREGHL)
inc hl
ld (MTREGHL),hl
jp MTLOOP
MTZERO: call MTBLOCK2
cp b
call z,MTBLOCK
ld a,b
inc a
ld (MTCOUNTERC),a
call MTINCHL2
jr MTBACK
MTHUM: call MTINCVALS
call MTHUMBLOCK
ld hl,(MTREGTM)
xor a
ld (hl),a
inc hl
ld (MTREGTM),hl
call MTINCHL2
jr MTBACK
MTFF: call MTINCVALS
call MTHUMBLOCK
ld hl,(MTREGTM)
ld a,0ffh
ld (hl),a
inc hl
ld (MTREGTM),hl
pop bc
pop de
pop hl
ret
MTREGHL: dw 0
MTREGHL2: dw 0
MTCOUNTER: db 0
MTCOUNTERC: db 0
MTREGTM: dw 0
MTREGTO: dw 0
MTREGBC: dw 0
; --------------------- end | procedure to created correct TXT for procedure INITMENU
; --------------------- begin | procedure to clear inverted bar
IMCLEARBAR: push af
push bc
ld hl,(IMPREGDE2)
ld a,(IMBART)
ld b,a
ld a,32
IMCBLOOP: call WVBYTE
inc hl
djnz IMCBLOOP
pop bc
pop af
ret
; --------------------- end | procedure to clear inverted bar
IMBKPRINT: ld hl,(IMREGHL)
ld de,(IMREGDE)
call LDIRVM
ld a,(IMPOSIT)
ld b,a
ld a,(IMCOUNTER)
cp b
call z,IMPINVERT
ret
; --------------------- begin | procedure to create menu
INITMENU: ld a,b
ld (IMPOSIT),a
ld a,c
ld (IMBART),a
ld a,1
ld (IMCOUNTER),a
IMLOOP0: ld (IMREGHL),hl
ld (IMREGDE),de
ld bc,0
IMLOOP: ld a,(hl)
and a
jr z,IMPWORD
cp 0ffh
jp z,IMBKPRINT
inc bc
inc hl
jr IMLOOP
IMPWORD: inc hl
ld (IMREGHL2),hl
call IMBKPRINT
inc a
ld (IMCOUNTER),a
ld hl,40
ld de,(IMREGDE)
add hl,de
push hl
pop de
ld hl,(IMREGHL2)
jr IMLOOP0
IMREGHL: dw 0
IMREGHL2: dw 0
IMREGDE: dw 0
IMCOUNTER: db 0
IMPOSIT: db 0
IMBART: db 0
; --------------------- end | procedure to create menu
; --------------------- begin | procedure to create inverted bar
IMPPMBAR: ld a,(IMBART)
ld hl,0
ld l,a
add hl,hl
add hl,hl
add hl,hl
push hl
pop bc
ld hl,800h
IMBARLOOP: ld a,0ffh
call WVBYTE
inc hl
dec bc
ld a,c
or b
jr nz,IMBARLOOP
call IMPPMASK
ret
; --------------------- end | procedure to create inverted bar
; --------------------- begin | procedure to create inverted character mask
IMPPMASK: ld hl,(IMPREGDE2)
ld a,(IMBART)
ld b,a
xor a
IPMASKLOOP: call WVBYTE
inc a
inc hl
djnz IPMASKLOOP
ret
; --------------------- end | procedure to create inverted character mask
; --------------------- begin | procedure to move bytes VRAM -> VRAM
IMPMOVE: ld b,8
IMPLOOP2: ld hl,(IMPREGHL2)
call RVBYTE
cpl
ld hl,(IMPREGDE)
call WVBYTE
ld hl,(IMPREGHL2)
inc hl
ld (IMPREGHL2),hl
ld hl,(IMPREGDE)
inc hl
ld (IMPREGDE),hl
djnz IMPLOOP2
ret
; --------------------- end | procedure to move bytes VRAM -> VRAM
; --------------------- begin | procedure to create inverted character
IMPINVERT: push af
ld de,(IMREGDE)
ld (IMPREGDE2),de
call IMPPMBAR
ld de,800h
ld (IMPREGDE),de
ld hl,(IMREGHL)
ld (IMPREGHL),hl
IMPLOOP: ld hl,(IMPREGHL)
ld a,(hl)
inc hl
ld (IMPREGHL),hl
and a
jr z,IMPFIM
cp 0ffh
jr z,IMPFIM
ld hl,0
ld l,a
add hl,hl
add hl,hl
add hl,hl
ld de,800h
add hl,de
ld (IMPREGHL2),hl
call IMPMOVE
jr IMPLOOP
IMPFIM: pop af
ret
IMPREGHL: dw 0
IMPREGHL2: dw 0
IMPREGDE: dw 0
IMPREGDE2: dw 0
; --------------------- end | procedure to create inverted character
; --------------------- begin | procedure to write byte in vram
WVBYTE: di
push hl
push de
push bc
push af
ld a,l
out (099h),a
ld a,h
and 3fh
or 40h
out (099h),a
ex (sp),hl
ex (sp),hl
pop af
out (098h),a
pop bc
pop de
pop hl
ret
; --------------------- end | procedure to write byte in vram
; --------------------- begin | procedure to read byte in vram
RVBYTE: di
push hl
push de
push bc
ld a,l
out (099h),a
ld a,h
and 3fh
out (099h),a
ex (sp),hl
ex (sp),hl
in a,(098h)
pop bc
pop de
pop hl
ret
; --------------------- end | procedure to read byte in vram
; --------------------- BEGIN | PROCEDURE TO MULTIPLY NUMBERS (BC*DE=HL)
MULTI: ld a,b
ld b,16
M16LOOP: add hl,hl
sla c
rla
jr nc,M16NO
add hl,de
M16NO: djnz M16LOOP
ret
; --------------------- END | PROCEDURE TO MULTIPLY NUMBERS
; --------------------- BEGIN | PROCEDURE TO PRINT HEX BYTE
PRINTBYTE: PUSH AF
PUSH HL
PUSH DE
PUSH BC
PUSH HL
LD B,A
AND 0F0H
RRCA
RRCA
RRCA
RRCA
LD HL,HEXNUMBERS
LD DE,0
LD E,A
ADD HL,DE
LD A,(HL)
POP HL
CALL WVBYTE
INC HL
PUSH HL
LD A,B
AND 0FH
LD HL,HEXNUMBERS
LD DE,0
LD E,A
ADD HL,DE
LD A,(HL)
POP HL
CALL WVBYTE
POP BC
POP DE
POP HL
POP AF
RET
; --------------------- END | PROCEDURE TO PRINT HEX BYTE
TXTOUT: db 'Option: 01 | Suboption: 01'
HEXNUMBERS: db '0123456789ABCDEF'
MMREGHL: dw 0
MMREGDE: dw 0
MMREGBC: dw 0
ADDRSUB: dw 0
ADDRORDER: dw 0
SUBVALS: dw 0,0,0,0,0,0,0,0,0
TXTMENU: db 0
end start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment