Page 6 of 8
"Hello, World!" with cc65
Posted: Sat Oct 17, 2020 8:13 pm
by geek504
Quick question from you C64'ers... (I'm from Apple-land):
I found many references to the routines below:
CHROUT = $FFD2
STROUT = $AB1E
But in X16 Programmer's Reference: Commodore 64 API Compatibility
Quote
$FFD2: BSOUT – write character
$FFF0: PLOT – read/write cursor position
$FFD2 is given a different name BSOUT... why?
Why not use STROUT directly? Is it compatible with X16? It uses a different memory address... it's not ROM?
Is PLOT the routine used to set LOCATE (or HTAB/VTAB)?
Why did the thread's "Hello World" explicitly print a newline? Couldn't the NEWLINE be added to the string? Do you even need it?
; print newline
lda #NEWLINE
jsr CHROUT
rts
Quote
$FFCF: BASIN – get character
$FFE4: GETIN – get character from keyboard
Lastly, does BASIC's GET command use BASIN or GETIN? Is there a keyboard strobe that needs to be reset before reading in the character?
"Hello, World!" with cc65
Posted: Sun Oct 18, 2020 1:05 am
by Ender
From what I can tell, CHROUT and BSOUT are simply two different names for the same function. Some references call it BSOUT, some CHROUT. I'm not sure what "STROUT" is. Kernal routines start with "FF" and on the X16 $AB1E would be in RAM, so no code would be there unless your program put something there.
For the other question, it looks like BASIC GET does a lot of things, but when I skimmed it looking for a kernal call, it seems that it calls GETIN, which simply removes and returns a character from the keyboard queue.
"Hello, World!" with cc65
Posted: Sun Oct 18, 2020 1:22 am
by geek504
24 minutes ago, Ender said:
Kernal routines start with "FF" and on the X16 $AB1E would be in RAM
After some Googling, I found that STROUT is found in BASIC ROM on the C64 ($A000-BFFF). It's part of the BASIC PRINT command that outputs a string.
Commander X16 BASIC ROM is found at $C000-FFFF in Bank #4. I need to find out the address of X16's STROUT and how to JSR to that address... maybe that FARJSR subroutine?
Further analysis of X16 BASIC ROM source code, I found the start of STROUT routine in
~\x16-rom-master\basic\code7.s but it doesn't give me an address.
"Hello, World!" with cc65
Posted: Sun Oct 18, 2020 1:41 am
by SlithyMatt
5 hours ago, geek504 said:
Why did the thread's "Hello World" explicitly print a newline? Couldn't the NEWLINE be added to the string? Do you even need it?
That's a limitation of the ca65 assembler. You can't have an inline control character in a string constant. So, you have to either do an awkward list that has a newline and then a null (.byte "Hello, World!", NEWLINE,0), or just do a newline print in the code.
"Hello, World!" with cc65
Posted: Sun Oct 18, 2020 1:44 am
by Ender
8 minutes ago, geek504 said:
After some Googling, I found that STROUT is found in BASIC ROM on the C64 ($A000-BFFF). It's part of the BASIC PRINT command that outputs a string.
Commander X16 BASIC ROM is found at $C000-FFFF in Bank #4. I need to find out the address of X16's STROUT and how to JSR to that address... maybe that FARJSR subroutine?
Well, if the address is a spot within the BASIC code, then it's not a vector kernal routine, therefore something not meant to be used by the user. That said, it looks like it's $CD52 on bank 4 on the X16 (in the source code it's in basic/code7.s). You can play around with it if you want, but it probably requires a very specific setup to actually use it.
"Hello, World!" with cc65
Posted: Sun Oct 18, 2020 1:48 am
by geek504
7 minutes ago, Ender said:
Well, if the address is a spot within the BASIC code, then it's not a vector kernal routine, therefore something not meant to be used by the user. That said, it looks like it's $CD52 on bank 4 on the X16 (in the source code it's in basic/code7.s). You can play around with it if you want, but it probably requires a very specific setup to actually use it.
Just like so... on a C64 which should be equivalent on the X16. How does one call a function in ROM BANK #4?
Quote
; hw.s: example using BASIC ROM routine to output a string
; cl65 hw.s -o hw.prg -C c64-asm.cfg -u __EXEHDR__
LOWERCASE = $0E
CLRSCR = $93
WHITE = $05
LTBLUE = $9A
STROUT = $AB1E
LDA #<msg
LDY #>msg
JMP STROUT
msg:
.byte LOWERCASE, CLRSCR, WHITE, "Hello World!", LTBLUE, 0
"Hello, World!" with cc65
Posted: Sun Oct 18, 2020 1:52 am
by Ender
Oh cool, well if you already have an example of how to use it, then it's worth a try. You'd just change the definition of STROUT to $CD52, and make sure to change the ROM bank to 4 first.
"Hello, World!" with cc65
Posted: Sun Oct 18, 2020 1:52 am
by SlithyMatt
As the X16 will have flashable ROM, it's really a bad idea to try to call code inside the BASIC interpreter. You won't know what build someone is using, but the published Kernal API should be stable, so stick with that.
"Hello, World!" with cc65
Posted: Sun Oct 18, 2020 1:59 am
by geek504
2 minutes ago, SlithyMatt said:
As the X16 will have flashable ROM, it's really a bad idea to try to call code inside the BASIC interpreter. You won't know what build someone is using, but the published Kernal API should be stable, so stick with that.
I'm thinking about saving work, time, and RAM by using pre-made BASIC routines in one's assembly code, e.g. TAN, COS, *, \, PRINT, etc.
Once the BASIC ROM is stable enough, it should be safe to use. To avoid all this headache, maybe a JUMP TABLE would be a nice idea.
Eventually it will be used in my INTEGER BASIC compiler because it doesn't have floating-point math
?
"Hello, World!" with cc65
Posted: Sun Oct 18, 2020 2:26 am
by SlithyMatt
26 minutes ago, geek504 said:
Eventually it will be used in my INTEGER BASIC compiler because it doesn't have floating-point math ?
That's probably your best course of action. Have a nice, reusable piece of code that runs efficiently and then make it available to other languages.