Files
z80_monitor/apps/casette/tape_loader.asm
T
2026-10-05 11:46:58 +02:00

121 lines
2.2 KiB
NASM

.include "bios.inc"
.area TAPELOAD (ABS)
.org TAPE_LOADER_ROM_ADDRESS
TAPE_PORT = 0x18
MAX_BLOCK_SIZE = 0x100
STACK_TOP = 0xBFFF
WORK_BASE = 0xB000
OLD_SP = WORK_BASE + 0x00 ; word
OLD_IFF = WORK_BASE + 0x02 ; byte
BLOCK_BUFFER = WORK_BASE + 0x100 ; MAX_BLOCK_SIZE
; #################################################3
; Entry
; #################################################3
tape_loader:
ld (OLD_SP),sp
; Save interrupt state.
ld a,i
jp po,iff_was_off
ld a,#1
jr save_iff
iff_was_off:
xor a
save_iff:
ld (OLD_IFF),a
di
ld sp,#STACK_TOP
main:
; Initial message.
ld hl,#msg_start
call print_string_ei
; #################################################3
; Exit
; #################################################3
exit:
ei
call BIOS_FLUSH
di
ld sp,(OLD_SP)
; Return code 0
ld a,#0
ld c,a
; Restore caller's interrupt state.
ld a,(OLD_IFF)
or a
ld a,c
jr z,return_di
ei
ret
return_di:
ret
; #################################################3
; IO Helper functions
; #################################################3
print_string_ei:
ei
call print_string
call BIOS_FLUSH
di
ret
print_string:
ld a,(hl)
or a
ret z
call BIOS_PUTC
inc hl
jr print_string
print_crlf:
ld a,#13
call BIOS_PUTC
ld a,#10
jp BIOS_PUTC
print_hex16:
push hl
ld a,h
call print_hex8
pop hl
ld a,l
call print_hex8
ret
print_hex8:
push af
rrca
rrca
rrca
rrca
and #0x0F
call print_hex_nibble
pop af
and #0x0F
; fall through
print_hex_nibble:
cp #10
jr c,print_hex_digit
add a,#('A' - 10)
jp BIOS_PUTC
print_hex_digit:
add a,#'0'
jp BIOS_PUTC
; #################################################3
; Strings
; #################################################3
msg_start:
.ascii "TAPE DECODE TEST - PLAY TAPE"
.db 13,10,0