langsmoke/ref_z80

302 lines
4.5 KiB
Plaintext

.nolist
#include "tse.inc"
.list
.org saferam1-3
.db $BB,$6D
ret
flags_base .equ 89F0h
flags_size .equ 60
sp_size .equ 2
task_sp .equ 0
task_flags .equ task_sp + sp_size
task_end .equ task_flags + flags_size
maxblocksize .equ 100h
start:
jr startkrnl
jp verinfo
jp chkprog
jp exitshell
jp taskswitch
jp starttask
jp endtask
jp forceyield
verinfo
ld hl, %0000000001111111
majorver .equ 1
minorver .equ 6
ld bc, (majorver*256)+minorver
ret
startkrnl:
bcall(_runIndicOff)
ld bc, flags_size
ld hl, flags_base
ld de, sysflags
ldir
ld hl, shellprog
ld de, cprogram
bcall(_mov9b)
ld hl, cprogram
rst 20h
call starttask
cp 0
ret nz
call chkEnoughForBuffer
ld (sysstack), sp
jp taskenter
exitshell:
ld hl, (sysstack)
ld sp, hl
call cpy_prgm_out
ld hl, shellprog
rst 20h
call endtask
bcall(_clrScrnFull)
ld hl, 0
ld (currow), hl
ld hl, msg
bcall(_puts)
res onInterrupt, (iy+onFlags)
ret
forceyield:
ld hl, shellprog
rst 20h
call taskswitch
ret
taskswitch:
ld (tempword), sp
ld hl, (pptr_preserve)
push hl
ld de, (tempword)
ld (hl), e
inc hl
ld (hl), d
ld hl, op1
ld de, tprogram
bcall(_mov9b)
pop hl
inc hl
inc hl
ex de, hl
ld bc, flags_size
ld hl, flags_base
ldir
ld hl, 0
ld (currow), hl
set textInverse, (iy+textflags)
ld hl, plswait
bcall(_puts)
ld hl, (sysstack)
ld sp, hl
call chkEnoughForBuffer
call cpy_prgm_out
ld hl, tprogram
ld de, cprogram
bcall(_mov9b)
taskenter:
call chkEnoughForBuffer
call cpy_prgm_in
ld hl, (pptr_preserve)
inc hl
inc hl
ld bc, flags_size
ld de, flags_base
ldir
ld hl, (pptr_preserve)
bcall(_ldHLind)
ld sp, hl
ret
endtask:
call chkprog
cp 0
ret nz
ld hl, (fptr_prgtitle)
ld a, (hl)
cp ' '
ld a, 4
ret z
ld hl, (fptr_memreq)
bcall(_ldHLind)
ex de, hl
ld hl, task_end
add hl, de
push hl
push hl
ex de, hl
ld hl, (fptr_end)
or a
sbc hl, de
pop de
bcall(_delmem)
ld hl, (fptr_varsize)
bcall(_ldHLind)
pop bc
or a
sbc hl, bc
ex de, hl
ld hl, (fptr_varsize)
ld (hl), e
inc hl
ld (hl), d
ld hl, (fptr_prgtitle)
ld a, ' '
ld (hl), a
xor a
ret
isr.power_on:
ld a, kg_func
rowread
cp invmask(kb_2nd)
jr nz, isr.2nd_raised
res calc_on, (hl)
ld hl, isr.shut_down
push hl
jr isr.wait_on
isr.force_off:
ld hl, os.status_flags
res calc_on, (hl)
isr.shut_down:
di
push af
lcd_busy
ld a, $02
out (lcd_cmd_port), a
pop af
isr.off_loop:
push af
ld a, $36
out (irq_stat_port), a
ld a, $01
out (irq_mask_port), a
pop af
ei
halt
jr isr.off_loop
isr.2nd_raised:
ld hl, os.contrast
ld a, kg_arrows
rowread
bit kb_up, a
jr nz, isr.up_raised
isr.wait_up:
ld a, kg_arrows
rowread
bit kb_up, a
jr z, isr.wait_up
ld a, (hl)
inc a
jr z, isr.contrast_max
out (lcd_cmd_port), a
ld (hl), a
isr.contrast_max:
ld a, sk_up
ld (os.prev_key), a
JR ISR.END
ISR.UP_RAISED:
BIT KB_DOWN, A
JR NZ, ISR.END
ISR.WAIT_DOWN:
LD A, KG_ARROWS
ROWREAD
BIT KB_DOWN, A
JR Z, ISR.WAIT_DOWN
LD A, (HL)
CP $C0
JR Z, ISR.CONTRAST_MIN
DEC A
OUT (LCD_CMD_PORT), A
LD (HL), A
ISR.CONTRAST_MIN:
LD A, SK_DOWN
LD (OS.PREV_KEY), A
JR ISR.END
INIT:
DI
IM 1
IN A, (HW_PORT)
OR A
AND $80
JP NZ, INIT.BASIC
LD A, $81
OUT ($07), A
DEC A
OUT ($08), A
XOR A
OUT ($08), A
OUT ($05), A
OUT ($20), A
OUT ($30), A
OUT ($33), A
OUT ($36), A
LD A, $14
OUT ($29), A
INIT.BASIC:
XOR A
OUT (LINK_PORT), A
LD A, $01
OUT (IRQ_MASK_PORT), A
LD A, $76
OUT (IRQ_STAT_PORT), A
LD A, $41
OUT ($07), A
LD SP, $0000
LD HL, INIT.LCD_OUT
LD B, 5
INIT.LCD_LOOP:
LCD_BUSY
LD A, (HL)
INC HL
OUT (LCD_CMD_PORT), A
DJNZ INIT.LCD_LOOP
LD HL, $8000
LD DE, $8001
LD BC, $8000
LD (HL), 0
LDIR
LD A, $F0
LD (OS.CONTRAST), A
LD A, BITMASK(CALC_ON) | BITMASK(APS_ON)
LD (OS.STATUS_FLAGS), A
LD HL, APS_TIME
LD (OS.APS_TIMER), HL
LD HL, USER_RAM
LD (OS.FREE_MEM_PTR), HL
LD HL, $0000
LD (OS.TEMP_NUM), HL
IN A, (IRQ_STAT_PORT)
AND $08
JR NZ, $-4
CALL ISR.FORCE_OFF
CALL ZP.CCLEAR
CALL ZP.CREDRAW
CALL ZP.VBUFDISP
LD HL, INIT.STR_CLEAR
CALL ZP.CPUTS
CALL ZP.CDISP
JP INIT.ALL_GOOD
INIT.LCD_OUT .DB $18, $01, $F0, $40, $05
INIT.STR_CLEAR .DB "MEM CLEARED", 0
#INCLUDE "LIBSRC\\STRING\\TOKENIZE.Z80"
.ECHO "\N"
INIT.ALL_GOOD:
EI
ZP.CONSOLE: .EXPORT ZP.CONSOLE
LD HL, ZP.CONSOLE
PUSH HL
LD HL, OS.ARG_PTRS
LD DE, OS.ARG_PTRS + 1
LD (HL), 0
LD BC, 127
LDIR
CALL ZP.CGETS
LD HL, OS.BUFFER
LD D, H
LD E, L
LD IX, OS.ARG_PTRS
CALL ZP.TOKENIZE
LD A, C
LD (OS.ARG_COUNT), A
LD HL, (ARG(0))
CALL ZP.STRUPR
LDIR