program start label is back for library outputs

This commit is contained in:
Irmen de Jong 2025-01-28 18:55:47 +01:00
parent d0f15f1285
commit 8ce3204f93
3 changed files with 57 additions and 2 deletions

View File

@ -91,6 +91,7 @@ internal class ProgramAndVarsGen(
asmgen.out("; ---- library assembler program ----")
asmgen.out("* = ${options.loadAddress.toHex()}")
asmgen.out("prog8_program_start\t; start of program label")
asmgen.out(" jmp p8b_main.p8s_start")
// note: the jmp above has 2 effects:
// 1. it prevents 64tass from stripping away all procs as unused code

View File

@ -15,6 +15,9 @@ An example of a library file loaded in BASIC on the Commander X16:
.. image:: _static/x16library.png
:align: center
(On the Commodore-64 and such, it works identically but you have to type the SYS addresses in decimal notation)
Requirements
^^^^^^^^^^^^
@ -86,15 +89,22 @@ But the users of the library are none the wiser and it just seems as if it is pa
Loading and using the library
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Assuming the load address of the library is $A000:
Assuming the load address of the library is $A000 (40960):
**From BASIC**::
**From BASIC** (the example is from the Commander X16)::
LOAD "LIBRARY.BIN",8,1
SYS $A000 : REM TO INITIALIZE VARIABLES, REQUIRED!
SYS $A004 : REM CALL FIRST ROUTINE
SYS $A008 : REM CALL SECOND ROUTINE, ETC.
For the Commodore 64 and such this works the same but you'll have to type the SYS addresses as decimal numbers.
The Commander X16 also has the BLOAD command to load binary data files, where you have to specify the memory
location where the file has to be loaded to. But for Prog8 library files you don't have to do that, just use LOAD;
the correct address is in the header of the library file. Loading the library to a different memory address
is not possible, because it will only work on the address it was compiled for (it's not possible to create
position independent code on the 6502).
**From Prog8**::
%import diskio
@ -114,6 +124,48 @@ Assuming the load address of the library is $A000:
}
}
**From C**::
#include <cbm.h>
int main() {
void (*lib_init)(void) = (void (*)()) 0xa000;
void (*lib_func1)(void) = (void (*)()) 0xa004;
void (*lib_func2)(void) = (void (*)()) 0xa008;
cbm_load("library.bin", 8, 0);
lib_init();
lib_func1();
lib_func2();
return 0;
}
**From Assembly**::
; add error handling as desired.
ldy #>libname
ldx #<libname
lda #11
jsr $ffbd ; SETNAM
ldy #1
ldx #8
lda #1
jsr $ffba ; SETLFS
lda #0
ldx #0
ldy #0
jsr $ffd5 ; LOAD
lda #13
jsr $ffd2 ; CHROUT
jsr $A000 ; library init
jsr $A004 ; lib func 1
jsr $A008 ; lib func 2
rts
libname:
.text "library.bin"
Example library code
^^^^^^^^^^^^^^^^^^^^

View File

@ -14,6 +14,8 @@ Future Things and Ideas
- Kotlin: can we use inline value classes in certain spots?
- add float support to the configurable compiler targets
- for creating libraries, something like %jmptable( block.func1, block.func2, ... ) could be useful to create a compact jump table, and possibly generating extsub definitions as well. Problem: directives cannot span multiple lines atm.
- improve support for romable code (see github issue 149)
- Improve the SublimeText syntax file for prog8, you can also install this for 'bat': https://github.com/sharkdp/bat?tab=readme-ov-file#adding-new-syntaxes--language-definitions
- [problematic due to using 64tass:] better support for building library programs, where unused .proc are NOT deleted from the assembly.
Perhaps replace all uses of .proc/.pend/.endproc by .block/.bend will fix that with a compiler flag?