Код:
.Z80
ASEG
ORG 0100h
WORKADDR EQU 08100h
STACK equ buffer+512
;EXE-file header:
HEADER:
DB 'EXE' ; EXE Signature
DB 0 ; Version of EXE file
DW CODE-HEADER,0 ; Code offset (32bit)
DW 0 ; Primary loader size or 0 (no primary loader)
DW 0,0,0 ; Reserved
DW LOAD ; Loading address
DW START ; Starting address (register PC)
DW STACK ; Stack address (register SP)
DS 490,0 ; round to 512
CODE:
.phase WORKADDR
LOAD:
START: push ix ; IX=cmdline ptr (START-80h)
ld hl,cmdln
call puts
pop de ; cmdline=<length>< line>0000h<self>
push de
call hexde ; display cmdline address (hex)
ld a,':'
call putchar
pop hl ; hl=cmdline ptr
inc hl ; skip <length> byte
call puts ; display cmdline content
ld hl,pages
call puts
xor a ; 0000..3fff
call cpupage ; FB:82 ; display default page,xframe
ld a,1 ; 4000..7fff
call cpupage ; FF:A2
ld a,2 ; 8000..bfff
call cpupage ; F6:C2
ld a,3 ; c000..ffff
call cpupage ; FF:E2
;
ld b,4
ld hl,hmem0
call alloc ; allocate next 4 pages for 64kb TPA (page0..3)
jr c,cerr
ld hl,npages
call puts
ld hl,page0
call showpg ; display page0, page1
ld hl,page2
call showpg ; display page2, page3
;
ld hl,msg
call puts
;
; get BIOS version
ld c,0efh
ld hl,buffer ; ASCIIZ returned here
push hl
call sbios
push af
call nc,hexde ; if no error, DE = BIOS version number0
call space
pop af
pop hl ; hl=buffer
push af
call nc,puts ; if no error
pop af
cerr: ld hl,err ; if error
call c,puts
;
ld a,10
call putchar ; LF to move shell prompt line down
call inkey
;
ld b,4
ld hl,hmem0
call free ; free page0..3
jp exit
;
cpupage:call getcpupage
jr c,cerr
call hexbc
space: ld a,' '
jp putchar
;
showpg: ld d,(hl)
inc hl
inc hl
ld e,(hl)
call hexde ; display pageX, pageX+1
jp space
;
alloc: push bc ; reserve by 1 page, r.B times, i.e. B*16 kb
push hl
call getmem1
pop hl
jr c,retc
ld (hl),a ; store segment handle
inc hl
push hl
call getpage ; decode handle to phis. pageN
pop hl
retc: pop bc
ret c
ld (hl),a ; store pageN
inc hl
djnz alloc
ret
;
free: push bc
ld a,(hl)
or a
push hl
call nz,freemem
pop hl
inc hl
inc hl
pop bc
djnz free
ret
;
INCLUDE funcs
;
hmem0: db 0
page0: db 0
hmem1: db 0
page1: db 0
hmem2: db 0
page2: db 0
hmem3: db 0
page3: db 0
err: db "Error",0dh,0ah,0
cmdln: db 0dh,0ah,"CommandLine params: ",0
pages: db 0dh,0ah,0ah,"CPU 16kb default RAM pages:xframe(0,1,2,3): ",0
npages: db 0dh,0ah,0ah,"CPU 16kb reserved RAM pages(0,1,2,3): ",0
msg: db 0dh,0ah,0ah,"Hello, world!",0dh,0ah,0ah,"Press any key..."
crlf: db 0dh,0ah,0
buffer:
.dephase
END