added cx16.MCIOUT() kernal call

correct case of several other cx16 kernal calls.

corrected to upper case: cx16 kernal calls CLOSE_ALL, LKUPLA, LKUPSA, JSRFAR, PRIMM, MACPTR.
This commit is contained in:
Irmen de Jong 2023-10-09 22:10:36 +02:00
parent a5cd3728c9
commit 68e62e4bd2
7 changed files with 36 additions and 97 deletions

View File

@ -183,7 +183,7 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
asmgen.out(" sta (+)+0 | sty (+)+1")
asmgen.assignExpressionToRegister(fcall.args[2], RegisterOrPair.AY) // uword argument
asmgen.out("""
jsr cx16.jsrfar
jsr cx16.JSRFAR
+ .word 0
+ .byte 0""")
// note that by convention the values in A+Y registers are now the return value of the call.

View File

@ -301,22 +301,22 @@ close_end:
sub f_read(uword bufferpointer, uword num_bytes) -> uword {
; -- read from the currently open file, up to the given number of bytes.
; returns the actual number of bytes read. (checks for End-of-file and error conditions)
; NOTE: cannot be used to load into VRAM. Use vload() or call cx16.macptr() yourself with the vera data register as address.
; NOTE: cannot be used to load into VRAM. Use vload() or call cx16.MACPTR() yourself with the vera data register as address.
if not iteration_in_progress or not num_bytes
return 0
reset_read_channel()
list_blocks = 0 ; we reuse this variable for the total number of bytes read
; commander X16 supports fast block-read via macptr() kernal call
; commander X16 supports fast block-read via MACPTR() kernal call
uword readsize
while num_bytes {
readsize = 255
if num_bytes<readsize
readsize = num_bytes
readsize = cx16.macptr(lsb(readsize), bufferpointer, false)
readsize = cx16.MACPTR(lsb(readsize), bufferpointer, false)
if_cs
goto byte_read_loop ; macptr block read not supported, do fallback loop
goto byte_read_loop ; MACPTR block read not supported, do fallback loop
list_blocks += readsize
bufferpointer += readsize
if msb(bufferpointer) == $c0
@ -329,7 +329,7 @@ close_end:
}
return list_blocks ; number of bytes read
byte_read_loop: ; fallback if macptr() isn't supported on the device
byte_read_loop: ; fallback if MACPTR isn't supported on the device
%asm {{
lda bufferpointer
sta m_in_buffer+1
@ -360,7 +360,7 @@ m_in_buffer sta $ffff
; optimized for Commander X16 to use MACPTR block read kernal call
sub f_read_all(uword bufferpointer) -> uword {
; -- read the full contents of the file, returns number of bytes read.
; NOTE: cannot be used to load into VRAM. Use vload() or call cx16.macptr() yourself with the vera data register as address.
; NOTE: cannot be used to load into VRAM. Use vload() or call cx16.MACPTR() yourself with the vera data register as address.
if not iteration_in_progress
return 0

View File

@ -331,17 +331,16 @@ cx16 {
; spelling of the names is taken from the Commander X-16 rom sources
; supported C128 additions
romsub $ff4a = close_all(ubyte device @A) clobbers(A,X,Y)
romsub $ff59 = lkupla(ubyte la @A) clobbers(A,X,Y)
romsub $ff5c = lkupsa(ubyte sa @Y) clobbers(A,X,Y)
romsub $ff4a = CLOSE_ALL(ubyte device @A) clobbers(A,X,Y)
romsub $ff59 = LKUPLA(ubyte la @A) clobbers(A,X,Y)
romsub $ff5c = LKUPSA(ubyte sa @Y) clobbers(A,X,Y)
romsub $ff5f = screen_mode(ubyte mode @A, bool getCurrent @Pc) clobbers(X, Y) -> ubyte @A, bool @Pc ; note: X,Y size result is not supported, use SCREEN or get_screen_mode routine for that
romsub $ff62 = screen_set_charset(ubyte charset @A, uword charsetptr @XY) clobbers(A,X,Y) ; incompatible with C128 dlchr()
; not yet supported: romsub $ff65 = pfkey() clobbers(A,X,Y)
romsub $ff6e = jsrfar() ; following word = address to call, byte after that=rom/ram bank it is in
romsub $ff6e = JSRFAR() ; following word = address to call, byte after that=rom/ram bank it is in
romsub $ff74 = fetch(ubyte bank @X, ubyte index @Y) clobbers(X) -> ubyte @A
romsub $ff77 = stash(ubyte data @A, ubyte bank @X, ubyte index @Y) clobbers(X)
romsub $ff7a = cmpare(ubyte data @A, ubyte bank @X, ubyte index @Y) clobbers(X)
romsub $ff7d = primm()
romsub $ff7d = PRIMM()
; It's not documented what registers are clobbered, so we assume the worst for all following kernal routines...:
@ -395,7 +394,8 @@ romsub $fed5 = console_set_paging_message(uword msgptr @R0) clobbers(A,X,Y)
romsub $fecf = entropy_get() -> ubyte @A, ubyte @X, ubyte @Y
romsub $fecc = monitor() clobbers(A,X,Y)
romsub $ff44 = macptr(ubyte length @A, uword buffer @XY, bool dontAdvance @Pc) clobbers(A) -> bool @Pc, uword @XY
romsub $ff44 = MACPTR(ubyte length @A, uword buffer @XY, bool dontAdvance @Pc) clobbers(A) -> bool @Pc, uword @XY
romsub $feb1 = MCIOUT(ubyte length @A, uword buffer @XY, bool dontAdvance @Pc) clobbers(A) -> bool @Pc, uword @XY
romsub $ff47 = enter_basic(bool cold_or_warm @Pc) clobbers(A,X,Y)
romsub $ff4d = clock_set_date_time(uword yearmonth @R0, uword dayhours @R1, uword minsecs @R2, ubyte jiffies @R3) clobbers(A, X, Y)
romsub $ff50 = clock_get_date_time() clobbers(A, X, Y) -> uword @R0, uword @R1, uword @R2, ubyte @R3 ; result registers see clock_set_date_time()

View File

@ -937,7 +937,7 @@ memory (name, size, alignment)
You can only treat it as a pointer or use it in inline assembly.
callfar (bank, address, argumentword) -> uword ; NOTE: specific to cx16 target for now
Calls an assembly routine in another bank on the Commander X16 (using its ``jsrfar`` routine)
Calls an assembly routine in another bank on the Commander X16 (using its ``JSRFAR`` routine)
Be aware that ram OR rom bank may be changed depending on the address it jumps to!
The argumentword will be loaded into the A+Y registers before calling the routine.
The uword value that the routine returns in the A+Y registers, will be returned.

View File

@ -1,6 +1,8 @@
TODO
====
- make the adpcm example able to decode and play stereo music.
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
- [on branch: ir-less-branch-opcodes] IR: reduce the number of branch instructions such as BEQ, BEQR, etc (gradually), replace with CMP(I) + status branch instruction
- IR: reduce amount of CMP/CMPI after instructions that set the status bits correctly (LOADs? INC? etc), but only after setting the status bits is verified!
@ -53,6 +55,8 @@ Compiler:
Libraries:
- gfx2 cs_innerloop640() extend number of bytes cleared, and use vera fx cached writes
- gfx2 horizontal_line and vertical_line: use vera fx cached writes
- port monogfx, gf2, graphics to the vm
- use verafx transparent writes to speed up pixel plotting in gfx2 and monogfx modules (avoids read/mask/write)
- fix the problems in atari target, and flesh out its libraries.

View File

@ -181,7 +181,7 @@ processchunk_call jsr $ffff ; modified
ubyte readsize = 255
if msb(size)==0
readsize = lsb(size)
cx16.r2 = cx16.macptr(readsize, bonkbuffer, false) ; can't macptr directly to bonk ram
cx16.r2 = cx16.MACPTR(readsize, bonkbuffer, false) ; can't MACPTR directly to bonk ram
cx16.rombank(bonk)
sys.memcopy(bonkbuffer, cx16.r3, cx16.r2) ; copy to bonk ram
cx16.rombank(orig_rom_bank)
@ -192,9 +192,9 @@ processchunk_call jsr $ffff ; modified
sub readblock(uword size, uword address, bool dontAdvance) -> uword {
if msb(size)>=2
return cx16.macptr(0, address, dontAdvance) ; read 512 bytes
return cx16.MACPTR(0, address, dontAdvance) ; read 512 bytes
if msb(size)
return cx16.macptr(255, address, dontAdvance) ; read 255 bytes
return cx16.macptr(lsb(size), address, dontAdvance) ; read remaining number of bytes
return cx16.MACPTR(255, address, dontAdvance) ; read 255 bytes
return cx16.MACPTR(lsb(size), address, dontAdvance) ; read remaining number of bytes
}
}

View File

@ -1,83 +1,18 @@
%import diskio
%import textio
;%import math
;%import verafx
%zeropage basicsafe
%option no_sysinit
main {
%option verafxmuls
sub start() {
word w1 = -123
word w2 = 222
ubyte b2 = 222
byte sb2 = 111
txt.print_w(w1*w2)
txt.nl()
txt.print_w(w1*222)
txt.nl()
w1 = -123
w1 *= 222
txt.print_w(w1)
txt.nl()
w1 = -123
w1 *= w2
txt.print_w(w1)
txt.nl()
w1 = -123
w1 *= (w2-1)
txt.print_w(w1)
txt.nl()
w1 = -123
w1 *= b2
txt.print_w(w1)
txt.nl()
w1 = -123
w1 *= sb2
txt.print_w(w1)
txt.nl()
; txt.print_uw(math.mul16_last_upper())
; txt.nl()
; uword value1=5678
; uword value2=9999
; uword result = value1*value2
; uword upper16 = math.mul16_last_upper()
; txt.print_uw(result)
; txt.spc()
; txt.print_uw(upper16)
; txt.nl()
; const word MULTIPLIER = 431
;
; ; verify results:
; for value in -50 to 50 {
; if value*MULTIPLIER != verafx.muls(value, MULTIPLIER) {
; txt.print("verafx muls error\n")
; sys.exit(1)
; }
; }
;
;
; word value
; txt.print("verafx muls...")
; cbm.SETTIM(0,0,0)
; for value in -50 to 50 {
; repeat 250 void verafx.muls(value, MULTIPLIER)
; }
; txt.print_uw(cbm.RDTIM16())
; txt.nl()
;
; txt.print("6502 muls...")
; cbm.SETTIM(0,0,0)
; for value in -50 to 50 {
; repeat 250 cx16.r0s = value*MULTIPLIER
; }
; txt.print_uw(cbm.RDTIM16())
; txt.nl()
cx16.r1H = %00000001 ; enable auto-indent
cx16.r2L = 4
cx16.r2H = 80
cx16.r3L = 8
cx16.r3H = 11<<4 | 7; background_color<<4 | text_color
cx16.r4 = 0
cx16.r1L = 0
cx16.rombank($d)
%asm {{
ldx #2
ldy #64
jmp $c006
}}
}
}