Update CP/M libsys.

This commit is contained in:
David Given 2019-11-23 11:31:03 +01:00
parent 5e2974a23e
commit 17fa773f04
10 changed files with 155 additions and 55 deletions

View file

@ -54,6 +54,17 @@ typedef struct
} }
DPB; DPB;
typedef struct
{
uint8_t xlt[2]; /* address of translation vector */
uint8_t scratch[6]; /* BDOS scratchpad */
uint8_t dirbuf[2]; /* address of directory scratchpad */
uint8_t dpb[2]; /* address of DPB */
uint8_t csv[2]; /* address of disk change scratchpad */
uint8_t alv[2]; /* address of allocation bitmap */
}
DPH;
/* Access an unaligned field (see above). */ /* Access an unaligned field (see above). */
#define U16(ptr) (*(uint16_t*)(ptr)) #define U16(ptr) (*(uint16_t*)(ptr))
@ -129,8 +140,22 @@ extern void cpm_printstring0(const char* s);
#define cpm_get_user() cpm_get_set_user(0xff) #define cpm_get_user() cpm_get_set_user(0xff)
#define cpm_set_user(u) cpm_get_set_user(u) #define cpm_set_user(u) cpm_get_set_user(u)
extern uint8_t bios_conin(void); extern void cpm_bios_boot(void);
extern uint8_t bios_const(void); extern void cpm_bios_wboot(void);
extern void bios_conout(uint8_t c); extern uint8_t cpm_bios_const(void);
extern uint8_t cpm_bios_conin(void);
extern void cpm_bios_conout(uint8_t c);
extern void cpm_bios_list(uint8_t c);
extern void cpm_bios_punch(uint8_t c);
extern uint8_t cpm_bios_reader(void);
extern void cpm_bios_home(void);
extern DPH* cpm_bios_seldsk(uint8_t disk);
extern void cpm_bios_settrk(uint16_t track);
extern void cpm_bios_setsec(uint16_t sector);
extern void cpm_bios_setdma(void* dma);
extern uint8_t cpm_bios_read(void);
extern uint8_t cpm_bios_write(void);
extern uint8_t cpm_bios_listst(void);
extern uint16_t cpm_bios_sectran(uint8_t* table, uint16_t sector);
#endif #endif

22
plat/cpm/libsys/_bios.s Normal file
View file

@ -0,0 +1,22 @@
#
#include "asm.h"
! Calls a BIOS routine which returns its value in A.
! a = BIOS offset
.define call_bios_a
call_bios_a:
pop h ! pop return address
pop d ! pop parameter (possibly junk)
push d
push h
push b ! save FP as we'll corrupt it
mov b, d ! put parameter in BC
mov c, e
call call_bios_raw
pop b
mov e, a ! put result in DE
mvi d, 0
ret

View file

@ -0,0 +1,14 @@
#
#include "asm.h"
! Low level BIOS call routine. The entrypoint offset from WBOOT is in A.
! HL is corrupted on entry.
.define call_bios_raw
call_bios_raw:
lhld 1 ! get BIOS entrypoint + 3
add l ! add on offset (the -3 is supplied by the caller)
mov l, a
jnc .1
inr h
.1:
pchl ! call the routine

View file

@ -1,15 +0,0 @@
#
#include "asm.h"
.define _bios_conin
_bios_conin:
lhld 1
lxi d, 6
dad d
push b
call .pchl
pop b
mov e, a
mvi d, 0
ret

View file

@ -1,21 +0,0 @@
#
#include "asm.h"
.define _bios_conout
_bios_conout:
pop h ! pop return address
pop d ! pop parameter into DE
push d
push h
push b
mov c, e
lhld 1
lxi d, 9
dad d
call .pchl
pop b
ret

View file

@ -1,16 +0,0 @@
#
#include "asm.h"
.define _bios_const
_bios_const:
lhld 1
lxi d, 3
dad d
push b
call .pchl
pop b
mov e, a
mvi d, 0
ret

View file

@ -0,0 +1,31 @@
#
#include "asm.h"
! Calls the BIOS SECTRAN routine, which returns its result in HL.
.define _cpm_bios_sectran
_cpm_bios_sectran:
pop d ! pop return address
pop h ! pop translation table
shld trans_table
pop h ! pop sector number
shld sec_num
push h
push h
push d
push b ! save FP as we'll corrupt it
trans_table = . + 1
lxi d, 0
sec_num = . + 1
lxi b, 0
lda 0x30-3 ! BIOS offset from WBOOT to SECTRAN
call call_bios_raw
pop b
xchg ! DE = HL
ret

View file

@ -0,0 +1,22 @@
#
#include "asm.h"
! Calls the BIOS SELDSK routine, which returns its result in HL.
.define _cpm_bios_seldsk
_cpm_bios_seldsk:
pop h ! pop return address
pop d ! pop parameter
push d
push h
push b ! save FP as we'll corrupt it
mov b, d ! put parameter in BC
mov c, e
mvi a, 0x1b-3 ! offset from WBOOT to SELDSK
call call_bios_raw
pop b
xchg ! DE = HL
ret

View file

@ -45,6 +45,24 @@ local bdos_calls = {
[40] = "cpm_write_random_filled", [40] = "cpm_write_random_filled",
} }
local bios_calls = {
[ 6] = "cpm_bios_const",
[ 9] = "cpm_bios_conin",
[12] = "cpm_bios_conout",
[15] = "cpm_bios_list",
[18] = "cpm_bios_punch",
[21] = "cpm_bios_reader",
[24] = "cpm_bios_home",
-- Special: [27] = "cpm_bios_seldsk",
[30] = "cpm_bios_settrk",
[33] = "cpm_bios_setsec",
[36] = "cpm_bios_setdma",
[39] = "cpm_bios_read",
[42] = "cpm_bios_write",
[45] = "cpm_bios_listst",
-- Special: [48] = "cpm_bios_sectran",
}
local trap_calls = { local trap_calls = {
"EARRAY", "EARRAY",
"EBADGTO", "EBADGTO",
@ -83,6 +101,16 @@ for n, name in pairs(bdos_calls) do
} }
} }
end end
for n, name in pairs(bios_calls) do
generated[#generated+1] = normalrule {
name = name,
ins = { "./make_bios_call.sh" },
outleaves = { name..".s" },
commands = {
"%{ins[1]} "..n.." "..name.." > %{outs}"
}
}
end
for _, name in pairs(trap_calls) do for _, name in pairs(trap_calls) do
generated[#generated+1] = normalrule { generated[#generated+1] = normalrule {
name = name, name = name,

View file

@ -0,0 +1,10 @@
#!/bin/sh
cat <<EOF
#
#include "asm.h"
.define _$2
_$2:
mvi a, $1 - 3
jmp call_bios_a
EOF