mirror of
https://github.com/nanochess/pretty6502.git
synced 2025-09-25 23:16:31 +00:00
3719 lines
97 KiB
NASM
3719 lines
97 KiB
NASM
;
|
||
; CVBasic prologue (BASIC compiler for Colecovision)
|
||
;
|
||
; by Oscar Toledo G.
|
||
; https://nanochess.org/
|
||
;
|
||
; Creation date: Feb/27/2024.
|
||
; Revision date: Feb/29/2024. Turns off sound. Now it reads the controllers.
|
||
; Added 16-bit multiply, division, modulo, and abs.
|
||
; Added random generator. Added sound routines.
|
||
; Revision date: Mar/03/2024. Removed fname directive to use gasm80.
|
||
; Revision date: Mar/05/2024. Added support for Sega SG1000.
|
||
; Revision date: Mar/06/2024. Added ENASCR, DISSCR, and CPYBLK.
|
||
; Revision date: Mar/08/2024. Added modes 0, 1 and 2.
|
||
; Revision date: Mar/12/2024. Added support for MSX.
|
||
; Revision date: Mar/14/2024. Added _sgn16.
|
||
; Revision date: Mar/15/2024. Added upper 16k enable for MSX.
|
||
; Revision date: Apr/11/2024. Added support for formatting numbers. Added
|
||
; support for Super Game Module.
|
||
; Revision date: Apr/13/2024. Saved bytes in SG-1000 ROMs. Faster LDIRVM.
|
||
; Shorter mode setting subroutines.
|
||
; Revision date: Apr/26/2024. Interruption handler saves current bank.
|
||
; Revision date: Apr/27/2024. Music player now supports bank switching.
|
||
; Revision date: May/17/2024. Added delay for SG1000 and SC3000 controller
|
||
; support with keyboard (code by SiRioKD)
|
||
; Revision date: Jun/04/2024. SGM supported deleted NTSC flag.
|
||
; Revision date: Jun/07/2024. Keys 0-9, = and - emulate keypad in MSX.
|
||
; Revision date: Jun/17/2024. Added SVI-328 support.
|
||
; Revision date: Aug/01/2024. Added Sord M5 support.
|
||
; Revision date: Aug/02/2024. PSG label now defined by CVBasic. Added Memotech
|
||
; support.
|
||
; Revision date: Aug/08/2024. Added Soundic/Hanimex Pencil II support.
|
||
; Revision date: Aug/15/2024. Added support for Tatung Einstein. Added support
|
||
; for Casio PV-2000.
|
||
; Revision date: Aug/21/2024. Added keypad support for Memotech, Tatung Einstein,
|
||
; and Casio PV-2000.
|
||
; Revision date: Aug/30/2024. Changed mode bit to bit 3 (avoids collision
|
||
; with flicker flag).
|
||
; Revision date: Oct/15/2024. Added LDIRMV. Solved bug where asterisk and number
|
||
; keys values were inverted.
|
||
; Revision date: Nov/12/2024. Saves the VDP status.
|
||
;
|
||
|
||
JOYSEL: equ $c0
|
||
KEYSEL: equ $80
|
||
|
||
JOY1: equ $fc-$20*SG1000
|
||
JOY2: equ $ff-$22*SG1000
|
||
|
||
if COLECO
|
||
org $8000
|
||
if PENCIL
|
||
db "COPYRIGHT SOUNDIC"
|
||
jp START
|
||
jp nmi_handler
|
||
jp 0 ; rst $08
|
||
jp 0 ; rst $10
|
||
jp 0 ; rst $18
|
||
jp 0 ; rst $20
|
||
jp 0 ; rst $28
|
||
jp 0 ; rst $30
|
||
jp 0 ; rst $38
|
||
dw $0000
|
||
dw $0000
|
||
dw $0000
|
||
dw $0000
|
||
db "CVBASIC!POWERED BY!2024!"
|
||
else
|
||
db $55,$aa
|
||
dw 0
|
||
dw 0
|
||
dw 0
|
||
dw 0
|
||
dw START
|
||
|
||
jp 0 ; rst $08
|
||
jp 0 ; rst $10
|
||
jp 0 ; rst $18
|
||
jp 0 ; rst $20
|
||
jp 0 ; rst $28
|
||
jp 0 ; rst $30
|
||
jp 0 ; rst $38
|
||
|
||
jp nmi_handler
|
||
endif
|
||
endif
|
||
if SG1000+SVI
|
||
org $0000
|
||
di
|
||
ld sp,STACK
|
||
jp START
|
||
db $ff
|
||
jp 0
|
||
db $ff,$ff,$ff,$ff,$ff
|
||
jp 0
|
||
db $ff,$ff,$ff,$ff,$ff
|
||
jp 0
|
||
db $ff,$ff,$ff,$ff,$ff
|
||
jp 0
|
||
db $ff,$ff,$ff,$ff,$ff
|
||
jp 0
|
||
db $ff,$ff,$ff,$ff,$ff
|
||
jp 0
|
||
db $ff,$ff,$ff,$ff,$ff
|
||
jp nmi_handler ; It should be called int_handler.
|
||
endif
|
||
if MSX
|
||
ORG $4000
|
||
db "AB"
|
||
dw START
|
||
dw $0000
|
||
dw $0000
|
||
dw $0000
|
||
dw $0000
|
||
|
||
WRTPSG: equ $0093
|
||
RDPSG: equ $0096
|
||
|
||
endif
|
||
if SORD
|
||
ORG $2000
|
||
db $02 ; Avoid checking $4000
|
||
dw START ; Start address.
|
||
dw $002e ; Prestart address (just point to RET in BIOS).
|
||
endif
|
||
if PV2000
|
||
ORG $C000
|
||
jp START
|
||
endif
|
||
|
||
if MEMOTECH
|
||
if CPM
|
||
org $0100
|
||
else
|
||
org $40fc
|
||
dw rom_start
|
||
dw rom_end-rom_start
|
||
endif
|
||
rom_start:
|
||
jp START
|
||
db 0,0,0,0,0
|
||
dw nmi_handler
|
||
dw null_vector
|
||
dw null_vector
|
||
dw rom_start
|
||
|
||
null_vector:
|
||
ei
|
||
reti
|
||
endif
|
||
if EINSTEIN
|
||
org $0100
|
||
rom_start:
|
||
jp START
|
||
db 0,0,0,0,0
|
||
dw $0000
|
||
dw $0000
|
||
dw $0000
|
||
dw $0000
|
||
endif
|
||
if NABU
|
||
if CPM
|
||
org $0100
|
||
else
|
||
org $140d
|
||
endif
|
||
nop
|
||
nop
|
||
nop
|
||
jp START
|
||
times $100-($&255) db $ff
|
||
nabu_int:
|
||
dw null_vector
|
||
dw null_vector
|
||
dw keyboard_handler
|
||
dw nmi_handler
|
||
dw null_vector
|
||
dw null_vector
|
||
dw null_vector
|
||
dw null_vector
|
||
|
||
null_vector:
|
||
ei
|
||
reti
|
||
endif
|
||
|
||
if SVI
|
||
WRTPSG:
|
||
out ($88),a
|
||
push af
|
||
ld a,e
|
||
out ($8c),a
|
||
pop af
|
||
ret
|
||
|
||
RDPSG:
|
||
out ($88),a
|
||
push af
|
||
pop af
|
||
in a,($90)
|
||
ret
|
||
endif
|
||
|
||
if EINSTEIN
|
||
WRTPSG:
|
||
out ($02),a
|
||
push af
|
||
ld a,e
|
||
out ($03),a
|
||
pop af
|
||
ret
|
||
|
||
RDPSG:
|
||
out ($02),a
|
||
push af
|
||
pop af
|
||
in a,($02)
|
||
ret
|
||
endif
|
||
|
||
if NABU
|
||
WRTPSG:
|
||
out ($41),a
|
||
push af
|
||
ld a,e
|
||
out ($40),a
|
||
pop af
|
||
ret
|
||
|
||
RDPSG:
|
||
out ($41),a
|
||
push af
|
||
pop af
|
||
in a,($40)
|
||
ret
|
||
endif
|
||
|
||
if PV2000
|
||
WRTVDP:
|
||
ld a,b
|
||
ld (VDP+1),a
|
||
ld a,c
|
||
or $80
|
||
ld (VDP+1),a
|
||
ret
|
||
|
||
SETWRT:
|
||
ld a,l
|
||
ld (VDP+1),a
|
||
ld a,h
|
||
or $40
|
||
ld (VDP+1),a
|
||
ret
|
||
|
||
SETRD:
|
||
ld a,l
|
||
ld (VDP+1),a
|
||
ld a,h
|
||
and $3f
|
||
ld (VDP+1),a
|
||
ret
|
||
|
||
WRTVRM:
|
||
push af
|
||
call SETWRT
|
||
pop af
|
||
ld (VDP),a
|
||
ret
|
||
|
||
RDVRM:
|
||
push af
|
||
call SETRD
|
||
pop af
|
||
ex (sp),hl
|
||
ex (sp),hl
|
||
ld a,(VDP)
|
||
ret
|
||
|
||
FILVRM:
|
||
push af
|
||
call SETWRT
|
||
pop af
|
||
dec bc ; T-states (normal / M1)
|
||
.1: ld (VDP),a ; 13 14
|
||
dec bc ; 6 7
|
||
bit 7,b ; 8 10
|
||
jp z,.1 ; 10 11
|
||
; -- --
|
||
; 37 42
|
||
ret
|
||
|
||
LDIRMV:
|
||
ex de,hl
|
||
call SETRD
|
||
ex (sp),hl
|
||
ex (sp),hl
|
||
.1:
|
||
ld a,(VDP)
|
||
ld (de),a
|
||
inc de
|
||
dec bc
|
||
ld a,b
|
||
or c
|
||
jp nz,.1
|
||
ret
|
||
|
||
LDIRVM:
|
||
EX DE,HL
|
||
CALL SETWRT
|
||
EX DE,HL
|
||
DEC BC
|
||
INC C
|
||
LD A,B
|
||
LD B,C
|
||
INC A
|
||
LD C,A
|
||
.1:
|
||
LD A,(HL) ; 7 8
|
||
LD (VDP),A ; 13 14
|
||
INC HL ; 6 7
|
||
DJNZ .1 ; 13 14
|
||
DEC C ; 4 5
|
||
JP NZ,.1 ; 10 11
|
||
RET
|
||
else
|
||
WRTVDP:
|
||
ld a,b
|
||
out (VDP+1),a
|
||
ld a,c
|
||
or $80
|
||
out (VDP+1),a
|
||
ret
|
||
|
||
SETWRT:
|
||
ld a,l
|
||
out (VDP+1),a
|
||
ld a,h
|
||
or $40
|
||
out (VDP+1),a
|
||
ret
|
||
|
||
SETRD:
|
||
ld a,l
|
||
out (VDP+1),a
|
||
ld a,h
|
||
and $3f
|
||
out (VDP+1),a
|
||
ret
|
||
|
||
WRTVRM:
|
||
push af
|
||
call SETWRT
|
||
pop af
|
||
out (VDP),a
|
||
ret
|
||
|
||
if SG1000
|
||
db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff
|
||
|
||
; Located at $0066
|
||
ei ; NMI handler (pause button)
|
||
retn
|
||
endif
|
||
|
||
RDVRM:
|
||
push af
|
||
call SETRD
|
||
pop af
|
||
ex (sp),hl
|
||
ex (sp),hl
|
||
in a,(VDPR)
|
||
ret
|
||
|
||
FILVRM:
|
||
push af
|
||
call SETWRT
|
||
pop af
|
||
dec bc ; T-states (normal / M1)
|
||
.1: out (VDP),a ; 11 12
|
||
dec bc ; 6 7
|
||
bit 7,b ; 8 10
|
||
jp z,.1 ; 10 11
|
||
; -- --
|
||
; 35 40
|
||
ret
|
||
|
||
LDIRMV:
|
||
ex de,hl
|
||
call SETRD
|
||
ex (sp),hl
|
||
ex (sp),hl
|
||
.1:
|
||
in a,(VDP)
|
||
ld (de),a
|
||
if SORD
|
||
nop
|
||
endif
|
||
if SG1000+MEMOTECH+EINSTEIN
|
||
nop ; SG1000 is 3.58 mhz, but SC3000 is 4 mhz.
|
||
nop
|
||
endif
|
||
inc de
|
||
dec bc
|
||
ld a,b
|
||
or c
|
||
jp nz,.1
|
||
ret
|
||
|
||
LDIRVM:
|
||
ex de,hl
|
||
call SETWRT
|
||
ex de,hl
|
||
dec bc
|
||
inc c
|
||
ld a,b
|
||
ld b,c
|
||
inc a
|
||
ld c,VDP
|
||
.1:
|
||
if SORD
|
||
nop
|
||
endif
|
||
if SG1000+MEMOTECH+EINSTEIN
|
||
nop ; SG1000 is 3.58 mhz, but SC3000 is 4 mhz.
|
||
nop
|
||
endif
|
||
outi
|
||
jp nz,.1
|
||
dec a
|
||
jp nz,.1
|
||
ret
|
||
endif
|
||
|
||
LDIRVM3:
|
||
call .1
|
||
call .1
|
||
.1: push hl
|
||
push de
|
||
push bc
|
||
call LDIRVM
|
||
pop bc
|
||
pop de
|
||
ld a,d
|
||
add a,8
|
||
ld d,a
|
||
pop hl
|
||
ret
|
||
|
||
DISSCR:
|
||
call nmi_off
|
||
ld bc,$a201
|
||
call WRTVDP
|
||
jp nmi_on
|
||
|
||
ENASCR:
|
||
call nmi_off
|
||
ld bc,$e201
|
||
call WRTVDP
|
||
jp nmi_on
|
||
|
||
CPYBLK:
|
||
pop hl
|
||
ex af,af' |