mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-06-12 09:29:32 +00:00
- Documentation for .asm libraries fixes.
- Asm library code debug fixes. - Added test programs as explained in the documentation.
This commit is contained in:
parent
a0416a1a1d
commit
30e6aff441
|
@ -1,4 +1,4 @@
|
|||
## 2.11 Libraries
|
||||
## 2.11 .ASM Libraries
|
||||
|
||||
KickC has now a new facility that allows to create pre-compiled assembler libraries, with flexible **export** facilities, and use these libraries with easy **import** facilities.
|
||||
Throughout this section, we will refer to these libraries as **.asm libraries**, as the artefacts of libraries are actually kick assembler (kickass) .asm source files.
|
||||
|
@ -56,9 +56,9 @@ graph TD
|
|||
subgraph plane.c
|
||||
include["#include flight_lib_asm.h"]
|
||||
main[["int main() {
|
||||
flight_init( 1 );
|
||||
flight_route( 1, 270 );
|
||||
flight_direction( 1, 2000 ); }
|
||||
flight_init( 2 );
|
||||
flight_route( 2, 10 );
|
||||
flight_direction( 2, 2000 ); }
|
||||
"]]
|
||||
include-.->main
|
||||
end
|
||||
|
@ -85,7 +85,7 @@ graph TD
|
|||
|
||||
```
|
||||
|
||||
The `#pragma asm_library` specify that *flight_lib.c* is a library and can be compiled separately,
|
||||
The `#pragma asm_library` specifies that *flight_lib.c* is a library and can be compiled separately,
|
||||
generating 2 output files: a *flight_lib.asm* file (the .asm library) and
|
||||
*flight_lib_asm.h* (the _asm.h C header) that contains specific C function
|
||||
prototypes to be used by the main C program. The *flight_lib_asm.h* contains prototypes for the 3 flight functions, with .asm library directives to tell kickc that these functions are pre-compiled in *flight_lib.asm*.
|
||||
|
@ -162,7 +162,7 @@ Consider again the library C source file called *flight_lib.c*, as introduced ea
|
|||
|
||||
void __stackcall flight_init(char flightno);
|
||||
void __varcall flight_route(char flightno, int direction);
|
||||
char __varcall flight_direction(char flightno, signed char distance);
|
||||
void __varcall flight_direction(char flightno, signed char distance);
|
||||
|
||||
void __varcall flight_internal...;
|
||||
```
|
|
@ -167,7 +167,7 @@ directive
|
|||
| LOCAL_RESERVE PAR_BEGIN pragmaParam ( COMMA pragmaParam )* PAR_END #directiveReserveZp
|
||||
| CALLINGCONVENTION #directiveCallingConvention
|
||||
| ASM_IMPORT PAR_BEGIN pragmaParam PAR_END #directiveAsmImport
|
||||
| ASM_EXPORT PAR_BEGIN pragmaParam PAR_END #directiveAsmExport
|
||||
| ASM_EXPORT #directiveAsmExport
|
||||
;
|
||||
|
||||
stmtSeq
|
||||
|
|
|
@ -190,8 +190,10 @@ public class AsmLibrary extends AsmLine {
|
|||
StringBuilder headers = new StringBuilder();
|
||||
for(String procedureName: this.getProcedures()) {
|
||||
Procedure procedure = program.getScope().getProcedure(new ProcedureRef(procedureName));
|
||||
if(procedure != null)
|
||||
headers.append(generateHeader(procedure));
|
||||
if(procedure != null) {
|
||||
if(procedure.isAsmExportLibrary())
|
||||
headers.append(generateHeader(procedure));
|
||||
}
|
||||
}
|
||||
return headers.toString();
|
||||
}
|
||||
|
|
|
@ -697,6 +697,7 @@ public class Program {
|
|||
|
||||
for(String procedureName : procedures) {
|
||||
asmImportLibrary.addProcedure(procedureName, callingConvention);
|
||||
this.getLog().append("Procedure " + procedureName + " imported from .asm library " + asmImportLibrary.getName() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -752,8 +753,13 @@ public class Program {
|
|||
*/
|
||||
public AsmExportLibrary addAsmExportLibrary(String asmExportLibraryName, boolean exportAll) {
|
||||
Path asmExportResource = Paths.get(asmExportLibraryName + ".asm").toAbsolutePath();
|
||||
AsmExportLibrary asmLibrary = new AsmExportLibrary(asmExportLibraryName, asmExportResource, exportAll);
|
||||
this.asmExports.putIfAbsent(asmExportLibraryName, asmLibrary);
|
||||
AsmExportLibrary asmLibrary = asmExports.get(asmExportLibraryName);
|
||||
if(asmLibrary == null) {
|
||||
asmLibrary = new AsmExportLibrary(asmExportLibraryName, asmExportResource, exportAll);
|
||||
asmExports.put(asmExportLibraryName, asmLibrary);
|
||||
} else {
|
||||
asmLibrary.setExportAll(exportAll);
|
||||
}
|
||||
// this.addAsmResourceFile(asmExportResource);
|
||||
return asmLibrary;
|
||||
}
|
||||
|
@ -768,6 +774,7 @@ public class Program {
|
|||
*/
|
||||
public void addAsmExportProcedure(AsmExportLibrary asmExportLibrary, Procedure.CallingConvention callingConvention, String procedureName) {
|
||||
this.asmExports.get(asmExportLibrary.getName()).addProcedure(procedureName, callingConvention);
|
||||
this.getLog().append("Procedure " + procedureName + " exported to .asm library " + asmExportLibrary.getName() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -364,8 +364,8 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
|||
}
|
||||
}
|
||||
case CParser.PRAGMA_ASM_EXPORT -> { // Defines that an C routine is exported into the asm_library.
|
||||
String libraryName = pragmaParamString(pragmaParamFirst(ctx));
|
||||
Procedure.CallingConvention callingConvention = pragmaParamCallingConvention(ctx.pragmaParam(1));
|
||||
String libraryName = program.getAsmLibrary();
|
||||
Procedure.CallingConvention callingConvention = currentCallingConvention;
|
||||
List<String> procedures = pragmaParamAsmExportProcedures(ctx.pragmaParam());
|
||||
|
||||
AsmExportLibrary asmLibrary = program.addAsmExportLibrary(libraryName, false);
|
||||
|
@ -530,7 +530,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
|||
*/
|
||||
private List<String> pragmaParamAsmExportProcedures(List<KickCParser.PragmaParamContext> libraryParams) {
|
||||
List<String> procedures = new ArrayList<>();
|
||||
for(KickCParser.PragmaParamContext reserveCtx : libraryParams.subList(2, libraryParams.size())) {
|
||||
for(KickCParser.PragmaParamContext reserveCtx : libraryParams.subList(0, libraryParams.size())) {
|
||||
if(reserveCtx instanceof KickCParser.PragmaParamNameContext) {
|
||||
final TerminalNode name = ((KickCParser.PragmaParamNameContext) reserveCtx).NAME();
|
||||
// Only a single reserved address
|
||||
|
@ -753,7 +753,7 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
|||
// TODO: remove the library dependency and rework to one routine call.
|
||||
AsmExportLibrary asmExport = this.program.getAsmExportLibrary(procedure);
|
||||
if(asmExport != null) {
|
||||
if(!program.isProcedureAsmExport(procedure.getFullName())) {
|
||||
if(!program.isProcedureAsmExport(procedure.getFullName()) && asmExport.isExportAll()) {
|
||||
program.addAsmExportProcedure(asmExport, currentCallingConvention, procedure.getFullName());
|
||||
}
|
||||
this.program.setProcedureAsAsmExport(procedure, asmExport);
|
||||
|
@ -1499,7 +1499,10 @@ public class Pass0GenerateStatementSequence extends KickCParserBaseVisitor<Objec
|
|||
}
|
||||
|
||||
public Object visitDirectiveAsmExport(KickCParser.DirectiveAsmExportContext ctx) {
|
||||
String asmExport = ctx.pragmaParam().getText().toLowerCase(Locale.ENGLISH);
|
||||
String asmExport = program.getAsmLibrary();
|
||||
if(asmExport == null) {
|
||||
throw new CompileError("__asm_export directive used before #pragma asm_library declaration.", new StatementSource(ctx));
|
||||
}
|
||||
return new Directive.AsmExportDirective(asmExport);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,23 +6,27 @@
|
|||
#pragma var_model(zp)
|
||||
|
||||
// Declare this compilation to generate the conio_var_asm file!
|
||||
#pragma asm_library("conio_var")
|
||||
#pragma asm_library
|
||||
|
||||
// Declare the procedures to be exported to the .asm libary with the indicated calling convention.
|
||||
#pragma asm_export("conio_var", __varcall, __conio_var_start, conio_x16_init)
|
||||
#pragma asm_export("conio_var", __varcall, clrscr)
|
||||
#pragma asm_export("conio_var", __varcall, gotoxy)
|
||||
#pragma asm_export("conio_var", __varcall, wherex, wherey)
|
||||
#pragma asm_export("conio_var", __varcall, screensize, screensizex, screensizey, cputln )
|
||||
#pragma asm_export("conio_var", __stackcall, cputc )
|
||||
#pragma asm_export("conio_var", __varcall, cputcxy, cputs, cputsxy, textcolor, bgcolor, bordercolor )
|
||||
#pragma asm_export("conio_var", __varcall, kbhit, cursor, scroll )
|
||||
#pragma asm_export("conio_var", __varcall, screenlayer1, screenlayer2)
|
||||
#pragma asm_export("conio_var", __varcall, cpeekc, cpeekcxy)
|
||||
#pragma calling(__varcall)
|
||||
#pragma asm_export(__conio_var_start, conio_x16_init)
|
||||
#pragma asm_export(clrscr)
|
||||
#pragma asm_export(gotoxy)
|
||||
#pragma asm_export(wherex, wherey)
|
||||
#pragma asm_export(screensize, screensizex, screensizey, cputln )
|
||||
#pragma asm_export(cputcxy, cputs, cputsxy, textcolor, bgcolor, bordercolor )
|
||||
#pragma asm_export(kbhit, cursor, scroll )
|
||||
#pragma asm_export(screenlayer1, screenlayer2)
|
||||
#pragma asm_export(cpeekc, cpeekcxy)
|
||||
|
||||
// For the moment, allocate local procedure variables to memory.
|
||||
#pragma var_model(local_mem)
|
||||
#pragma calling(__stackcall)
|
||||
#pragma asm_export(cputc )
|
||||
|
||||
#pragma calling(__phicall)
|
||||
|
||||
// Allocate local procedure variables to memory.
|
||||
#pragma var_model(zp)
|
||||
|
||||
#include <conio.h>
|
||||
//#include <cx16-conio.h>
|
||||
|
||||
|
|
50
src/test/kc/library/flight/flight_lib.c
Normal file
50
src/test/kc/library/flight/flight_lib.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* Testing an export library flight_lib.asm file generation.
|
||||
|
||||
The result of this compile should result in:
|
||||
- A new flight_lib.asm file created in the compiler output directory.
|
||||
- A new flight_lib_asm.h file created in the compiler output directory.
|
||||
*/
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
#pragma var_model(zp)
|
||||
|
||||
// Register the compilation as an calc.asm export library output artefact.
|
||||
// There is no main() function!
|
||||
#pragma asm_library
|
||||
|
||||
// Register the exported procedures that should be included in the calc.asm export library.
|
||||
#pragma calling(__stackcall)
|
||||
#pragma asm_export(flight_init)
|
||||
#pragma calling(__varcall)
|
||||
#pragma asm_export(flight_route, flight_distance)
|
||||
#pragma calling(__phicall)
|
||||
|
||||
struct flight {
|
||||
char flightno;
|
||||
char direction;
|
||||
char distance;
|
||||
unsigned int x, y;
|
||||
};
|
||||
|
||||
struct flight flights[8];
|
||||
|
||||
void flight_init(char flightno) {
|
||||
flights[flightno].x = 0x8000;
|
||||
flights[flightno].y = 0x8000;
|
||||
}
|
||||
|
||||
void flight_route(char flightno, char direction) {
|
||||
flights[flightno].direction = direction;
|
||||
}
|
||||
|
||||
void flight_distance(char flightno, unsigned int distance) {
|
||||
flights[flightno].distance = distance;
|
||||
}
|
||||
|
||||
void flight_display() {
|
||||
|
||||
}
|
||||
|
||||
void flight_calculate() {
|
||||
|
||||
}
|
15
src/test/kc/library/flight/plane.c
Normal file
15
src/test/kc/library/flight/plane.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* Here we use the flight_lib.asm library functions.
|
||||
*/
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
#pragma var_model(zp)
|
||||
|
||||
// We include the flight_lib_asm.h generated C function prototype file.
|
||||
// This file contains the C function prototypes for import and usage.
|
||||
#include "flight_lib_asm.h"
|
||||
|
||||
void main() {
|
||||
flight_init(2);
|
||||
flight_route(2, 10);
|
||||
flight_distance(2, 0X2000);
|
||||
}
|
48
src/test/kc/library/flight2/flight_lib.c
Normal file
48
src/test/kc/library/flight2/flight_lib.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/* Testing an export library flight_lib.asm file generation.
|
||||
|
||||
The result of this compile should result in:
|
||||
- A new flight_lib.asm file created in the compiler output directory.
|
||||
- A new flight_lib_asm.h file created in the compiler output directory.
|
||||
*/
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
#pragma var_model(zp)
|
||||
|
||||
// Register the compilation as an calc.asm export library output artefact.
|
||||
// There is no main() function!
|
||||
#pragma asm_library
|
||||
|
||||
#pragma calling(__phicall)
|
||||
|
||||
struct flight {
|
||||
char flightno;
|
||||
char direction;
|
||||
char distance;
|
||||
unsigned int x, y;
|
||||
};
|
||||
|
||||
struct flight flights[8];
|
||||
|
||||
// Now with __asm_export directive!
|
||||
void __stackcall __asm_export flight_init(char flightno) {
|
||||
flights[flightno].x = 0x8000;
|
||||
flights[flightno].y = 0x8000;
|
||||
}
|
||||
|
||||
// Now with __asm_export directive!
|
||||
void __varcall __asm_export flight_route(char flightno, char direction) {
|
||||
flights[flightno].direction = direction;
|
||||
}
|
||||
|
||||
// Now with __asm_export directive!
|
||||
void __varcall __asm_export flight_distance(char flightno, unsigned int distance) {
|
||||
flights[flightno].distance = distance;
|
||||
}
|
||||
|
||||
void flight_display() {
|
||||
|
||||
}
|
||||
|
||||
void flight_calculate() {
|
||||
|
||||
}
|
15
src/test/kc/library/flight2/plane.c
Normal file
15
src/test/kc/library/flight2/plane.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* Here we use the flight_lib.asm library functions.
|
||||
*/
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
#pragma var_model(zp)
|
||||
|
||||
// We include the flight_lib_asm.h generated C function prototype file.
|
||||
// This file contains the C function prototypes for import and usage.
|
||||
#include "flight_lib_asm.h"
|
||||
|
||||
void main() {
|
||||
flight_init(2);
|
||||
flight_route(2, 10);
|
||||
flight_distance(2, 0X2000);
|
||||
}
|
49
src/test/kc/library/flight3/flight_lib.c
Normal file
49
src/test/kc/library/flight3/flight_lib.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* Testing an export library flight_lib.asm file generation.
|
||||
|
||||
The result of this compile should result in:
|
||||
- A new flight_lib.asm file created in the compiler output directory.
|
||||
- A new flight_lib_asm.h file created in the compiler output directory.
|
||||
*/
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
#pragma var_model(zp)
|
||||
|
||||
// Register the compilation as an calc.asm export library output artefact.
|
||||
// There is no main() function!
|
||||
#pragma asm_library
|
||||
|
||||
#pragma calling(__phicall)
|
||||
#pragma asm_export(flight_init, flight_route, flight_distance)
|
||||
|
||||
struct flight {
|
||||
char flightno;
|
||||
char direction;
|
||||
char distance;
|
||||
unsigned int x, y;
|
||||
};
|
||||
|
||||
struct flight flights[8];
|
||||
|
||||
// Now with __asm_export directive!
|
||||
void __stackcall flight_init(char flightno) {
|
||||
flights[flightno].x = 0x8000;
|
||||
flights[flightno].y = 0x8000;
|
||||
}
|
||||
|
||||
// Now with __asm_export directive!
|
||||
void __varcall flight_route(char flightno, char direction) {
|
||||
flights[flightno].direction = direction;
|
||||
}
|
||||
|
||||
// Now with __asm_export directive!
|
||||
void __varcall flight_distance(char flightno, unsigned int distance) {
|
||||
flights[flightno].distance = distance;
|
||||
}
|
||||
|
||||
void flight_display() {
|
||||
|
||||
}
|
||||
|
||||
void flight_calculate() {
|
||||
|
||||
}
|
15
src/test/kc/library/flight3/plane.c
Normal file
15
src/test/kc/library/flight3/plane.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* Here we use the flight_lib.asm library functions.
|
||||
*/
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
#pragma var_model(zp)
|
||||
|
||||
// We include the flight_lib_asm.h generated C function prototype file.
|
||||
// This file contains the C function prototypes for import and usage.
|
||||
#include "flight_lib_asm.h"
|
||||
|
||||
void main() {
|
||||
flight_init(2);
|
||||
flight_route(2, 10);
|
||||
flight_distance(2, 0X2000);
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
#if __asm_import__
|
||||
#else
|
||||
.segmentdef Code [start=%P]
|
||||
.segmentdef CodeConIO [startAfter="Code"]
|
||||
.segmentdef Data [startAfter="CodeConIO"]
|
||||
.segmentdef DataConIO [startAfter="Data"]
|
||||
#endif
|
|
@ -2,28 +2,31 @@
|
|||
// Create an .asm library of imporant conio functions.
|
||||
// Export to conio_var.asm
|
||||
|
||||
#pragma link("conio.ld")
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
#pragma var_model(zp)
|
||||
|
||||
// Declare this compilation to generate the conio_var_asm file!
|
||||
#pragma asm_library("conio_var")
|
||||
#pragma asm_library
|
||||
|
||||
// Declare the procedures to be exported to the .asm libary with the indicated calling convention.
|
||||
#pragma asm_export("conio_var", __varcall, __conio_var_start, conio_x16_init)
|
||||
#pragma asm_export("conio_var", __varcall, clrscr)
|
||||
#pragma asm_export("conio_var", __varcall, gotoxy)
|
||||
#pragma asm_export("conio_var", __varcall, wherex, wherey)
|
||||
#pragma asm_export("conio_var", __varcall, screensize, screensizex, screensizey, cputln )
|
||||
#pragma asm_export("conio_var", __stackcall, cputc )
|
||||
#pragma asm_export("conio_var", __varcall, cputcxy, cputs, cputsxy, textcolor, bgcolor, bordercolor )
|
||||
#pragma asm_export("conio_var", __varcall, kbhit, cursor, scroll )
|
||||
#pragma asm_export("conio_var", __varcall, screenlayer1, screenlayer2)
|
||||
#pragma asm_export("conio_var", __varcall, cpeekc, cpeekcxy)
|
||||
#pragma calling(__varcall)
|
||||
#pragma asm_export(__conio_var_start, conio_x16_init)
|
||||
#pragma asm_export(clrscr)
|
||||
#pragma asm_export(gotoxy)
|
||||
#pragma asm_export(wherex, wherey)
|
||||
#pragma asm_export(screensize, screensizex, screensizey, cputln )
|
||||
#pragma asm_export(cputcxy, cputs, cputsxy, textcolor, bgcolor, bordercolor )
|
||||
#pragma asm_export(kbhit, cursor, scroll )
|
||||
#pragma asm_export(screenlayer1, screenlayer2)
|
||||
#pragma asm_export(cpeekc, cpeekcxy)
|
||||
|
||||
// For the moment, allocate local procedure variables to memory.
|
||||
#pragma var_model(local_mem)
|
||||
#pragma calling(__stackcall)
|
||||
#pragma asm_export(cputc )
|
||||
|
||||
#pragma calling(__phicall)
|
||||
|
||||
// Allocate local procedure variables to memory.
|
||||
#pragma var_model(zp)
|
||||
|
||||
#include <conio.h>
|
||||
//#include <cx16-conio.h>
|
||||
|
|
|
@ -2,12 +2,10 @@
|
|||
|
||||
#include <lru-cache_asm.h>
|
||||
|
||||
#include <cx16.h>
|
||||
#include <conio.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <conio.h>
|
||||
#include <cx16-conio.h>
|
||||
#include <lru-cache.h>
|
||||
#include "lru-cache.h"
|
||||
#include <division.h>
|
||||
|
||||
volatile unsigned char row = 0;
|
||||
|
@ -26,59 +24,41 @@ void wait_key()
|
|||
|
||||
void display()
|
||||
{
|
||||
count++;
|
||||
col = (count / 8) * 16;
|
||||
row = (count % 8);
|
||||
|
||||
count = count % 32;
|
||||
|
||||
gotoxy(0, 9);
|
||||
lru_cache_display(0, 10);
|
||||
|
||||
lru_cache_display(0, 2);
|
||||
wait_key();
|
||||
}
|
||||
|
||||
lru_cache_data_t get(lru_cache_key_t key)
|
||||
{
|
||||
gotoxy(col, row);
|
||||
printf("get %04x", key);
|
||||
|
||||
gotoxy(0, 0);
|
||||
printf("get: %04x ", key);
|
||||
lru_cache_data_t data = lru_cache_get(lru_cache_index(key));
|
||||
|
||||
printf(":%04x", data);
|
||||
|
||||
display();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void set(lru_cache_key_t key, lru_cache_data_t data)
|
||||
{
|
||||
gotoxy(col, row);
|
||||
printf("set %04x:%04x", key, data);
|
||||
|
||||
gotoxy(0, 0);
|
||||
printf("set: %04x:%04x", key, data);
|
||||
lru_cache_set(lru_cache_index(key), data);
|
||||
|
||||
display();
|
||||
}
|
||||
|
||||
void insert(lru_cache_key_t key, lru_cache_data_t data)
|
||||
{
|
||||
gotoxy(col, row);
|
||||
printf("Add %04x:%04x", key, data);
|
||||
|
||||
gotoxy(0, 0);
|
||||
printf("add: %04x:%04x ", key, data);
|
||||
lru_cache_insert(key, data);
|
||||
|
||||
display();
|
||||
}
|
||||
|
||||
void delete (lru_cache_key_t key)
|
||||
{
|
||||
gotoxy(col, row);
|
||||
printf("Del %04x", key);
|
||||
|
||||
gotoxy(0, 0);
|
||||
printf("del: %04x ", key);
|
||||
lru_cache_delete(key);
|
||||
|
||||
display();
|
||||
}
|
||||
|
||||
|
@ -86,26 +66,24 @@ void main() {
|
|||
|
||||
lru_cache_init();
|
||||
|
||||
bgcolor(BLUE);
|
||||
textcolor(WHITE);
|
||||
clrscr();
|
||||
|
||||
insert(0x0, 0x0);
|
||||
// insert(0x80, 0x80);
|
||||
// insert(0x100, 0x100);
|
||||
// insert(0x1, 0x1);
|
||||
// insert(0x200, 0x200);
|
||||
// insert(0x2, 0x2);
|
||||
// insert(0x82, 0x82);
|
||||
// delete(0x0);
|
||||
// delete(0x100);
|
||||
// delete(0x80);
|
||||
// delete(0x1);
|
||||
// insert(0x201, 0x201);
|
||||
// insert(0x81, 0x81);
|
||||
// delete(0x2);
|
||||
// delete(0x81);
|
||||
// delete(0x201);
|
||||
// delete(0x82);
|
||||
// delete(0x200);
|
||||
insert(0x80, 0x80);
|
||||
insert(0x100, 0x100);
|
||||
insert(0x1, 0x1);
|
||||
insert(0x200, 0x200);
|
||||
insert(0x2, 0x2);
|
||||
insert(0x82, 0x82);
|
||||
delete(0x0);
|
||||
delete(0x100);
|
||||
delete(0x80);
|
||||
delete(0x1);
|
||||
insert(0x201, 0x201);
|
||||
insert(0x81, 0x81);
|
||||
delete(0x2);
|
||||
delete(0x81);
|
||||
delete(0x201);
|
||||
delete(0x82);
|
||||
delete(0x200);
|
||||
}
|
|
@ -10,31 +10,29 @@
|
|||
*
|
||||
*/
|
||||
|
||||
// // A link file is still needed, but this must be eliminated.
|
||||
#pragma link("lru-cache.ld")
|
||||
|
||||
// // Register the compilation as an export library output artefact.
|
||||
// // There is no main() function!
|
||||
#pragma asm_library
|
||||
#pragma calling(__varcall)
|
||||
|
||||
#pragma var_model(local_mem)
|
||||
#pragma var_model(zp)
|
||||
|
||||
// #pragma asm_export("lru_cache", __varcall, lru_cache_init)
|
||||
// #pragma asm_export("lru_cache", __varcall, lru_cache_find_last)
|
||||
// #pragma asm_export("lru_cache", __varcall, lru_cache_is_max)
|
||||
// #pragma asm_export("lru_cache", __varcall, lru_cache_index)
|
||||
// #pragma asm_export("lru_cache", __varcall, lru_cache_get)
|
||||
// #pragma asm_export("lru_cache", __varcall, lru_cache_set)
|
||||
// #pragma asm_export("lru_cache", __varcall, lru_cache_data)
|
||||
// #pragma asm_export("lru_cache", __varcall, lru_cache_insert)
|
||||
// #pragma asm_export("lru_cache", __varcall, lru_cache_delete)
|
||||
// #pragma asm_export("lru_cache", __varcall, lru_cache_display)
|
||||
#pragma asm_export(lru_cache_init)
|
||||
#pragma asm_export(lru_cache_find_last)
|
||||
#pragma asm_export(lru_cache_is_max)
|
||||
#pragma asm_export(lru_cache_index)
|
||||
#pragma asm_export(lru_cache_get)
|
||||
#pragma asm_export(lru_cache_set)
|
||||
#pragma asm_export(lru_cache_data)
|
||||
#pragma asm_export(lru_cache_insert)
|
||||
#pragma asm_export(lru_cache_delete)
|
||||
#pragma asm_export(lru_cache_display)
|
||||
|
||||
#pragma calling(__phicall)
|
||||
|
||||
#define LRU_CACHE_MAX 96
|
||||
#define LRU_CACHE_MAX 24
|
||||
#define LRU_CACHE_SIZE 32
|
||||
|
||||
#include <cx16.h>
|
||||
#include "lru-cache.h"
|
||||
#include <conio.h>
|
||||
#include <stdio.h>
|
||||
|
@ -361,15 +359,13 @@ void lru_cache_display(char x, char y) {
|
|||
gotoxy(x, y);
|
||||
|
||||
printf("least recently used cache statistics\n");
|
||||
printf("size = %3u, first = %2x, last = %2x, count = %2x\n\n", LRU_CACHE_SIZE, lru_cache.first, lru_cache.last, lru_cache.count);
|
||||
|
||||
printf("least recently used hash table\n\n");
|
||||
printf("size:%02x, first:%02x, last:%02x, cnt:%2x\n\n", LRU_CACHE_SIZE, lru_cache.first, lru_cache.last, lru_cache.count);
|
||||
|
||||
printf(" ");
|
||||
do {
|
||||
printf(" %1x/%1x ", col, col + 8);
|
||||
col++;
|
||||
} while (col < 8);
|
||||
} while (col < 4);
|
||||
printf("\n");
|
||||
|
||||
col = 0;
|
||||
|
@ -386,7 +382,7 @@ void lru_cache_display(char x, char y) {
|
|||
printf(" ----:--");
|
||||
}
|
||||
index++;
|
||||
} while (index < index_row + 8);
|
||||
} while (index < index_row + 4);
|
||||
printf("\n");
|
||||
|
||||
index = index_row;
|
||||
|
@ -395,11 +391,11 @@ void lru_cache_display(char x, char y) {
|
|||
printf(" %02x:", lru_cache.next[index]);
|
||||
printf("%02x ", lru_cache.prev[index]);
|
||||
index++;
|
||||
} while (index < index_row + 8);
|
||||
} while (index < index_row + 4);
|
||||
printf("\n");
|
||||
|
||||
index_row += 8;
|
||||
} while (index_row < 128);
|
||||
index_row += 4;
|
||||
} while (index_row < 4*4*2);
|
||||
|
||||
printf("\n");
|
||||
|
||||
|
@ -409,7 +405,7 @@ void lru_cache_display(char x, char y) {
|
|||
lru_cache_index_t count = 0;
|
||||
col = 0;
|
||||
|
||||
while (count < lru_cache.size) {
|
||||
while (count < 8) {
|
||||
if (count < lru_cache.count)
|
||||
printf(" %4x", lru_cache.key[index]);
|
||||
else
|
||||
|
|
33
src/test/kc/library/lru-cache2/conio_var.c
Normal file
33
src/test/kc/library/lru-cache2/conio_var.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
|
||||
// Create an .asm library of imporant conio functions.
|
||||
// Export to conio_var.asm
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
#pragma var_model(zp)
|
||||
|
||||
// Declare this compilation to generate the conio_var_asm file!
|
||||
#pragma asm_library
|
||||
|
||||
// Declare the procedures to be exported to the .asm libary with the indicated calling convention.
|
||||
#pragma calling(__varcall)
|
||||
#pragma asm_export(__conio_var_start, conio_x16_init)
|
||||
#pragma asm_export(clrscr)
|
||||
#pragma asm_export(gotoxy)
|
||||
#pragma asm_export(wherex, wherey)
|
||||
#pragma asm_export(screensize, screensizex, screensizey, cputln )
|
||||
#pragma asm_export(cputcxy, cputs, cputsxy, textcolor, bgcolor, bordercolor )
|
||||
#pragma asm_export(kbhit, cursor, scroll )
|
||||
#pragma asm_export(screenlayer1, screenlayer2)
|
||||
#pragma asm_export(cpeekc, cpeekcxy)
|
||||
|
||||
#pragma calling(__stackcall)
|
||||
#pragma asm_export(cputc )
|
||||
|
||||
#pragma calling(__phicall)
|
||||
|
||||
// Allocate local procedure variables to memory.
|
||||
#pragma var_model(zp)
|
||||
|
||||
#include <conio.h>
|
||||
//#include <cx16-conio.h>
|
||||
|
|
@ -2,82 +2,55 @@
|
|||
|
||||
#include <lru-cache_asm.h>
|
||||
|
||||
|
||||
#include <cx16.h>
|
||||
#include <conio.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <conio.h>
|
||||
#include <cx16-conio.h>
|
||||
#include <lru-cache.h>
|
||||
#include "lru-cache.h"
|
||||
#include <division.h>
|
||||
|
||||
// lru_cache_table_t lru_cache;
|
||||
|
||||
volatile unsigned char row = 0;
|
||||
volatile unsigned char col = 0;
|
||||
volatile unsigned char count = 0;
|
||||
|
||||
void wait_key()
|
||||
{
|
||||
while (!kbhit())
|
||||
;
|
||||
// while (!kbhit())
|
||||
// ;
|
||||
}
|
||||
|
||||
void display()
|
||||
{
|
||||
col = (count / 8) * 16;
|
||||
row = (count % 8);
|
||||
|
||||
count = count % 32;
|
||||
|
||||
lru_cache_display(0, 9);
|
||||
|
||||
count++;
|
||||
|
||||
// wait_key();
|
||||
lru_cache_display(0, 2);
|
||||
wait_key();
|
||||
}
|
||||
|
||||
lru_cache_data_t get(lru_cache_key_t key)
|
||||
{
|
||||
gotoxy(col, row);
|
||||
printf("get %04x", key);
|
||||
|
||||
gotoxy(0, 0);
|
||||
printf("get: %04x ", key);
|
||||
lru_cache_data_t data = lru_cache_get(lru_cache_index(key));
|
||||
|
||||
printf(":%04x", data);
|
||||
|
||||
display();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void set(lru_cache_key_t key, lru_cache_data_t data)
|
||||
{
|
||||
gotoxy(col, row);
|
||||
printf("set %04x:%04x", key, data);
|
||||
|
||||
gotoxy(0, 0);
|
||||
printf("set: %04x:%04x", key, data);
|
||||
lru_cache_set(lru_cache_index(key), data);
|
||||
|
||||
display();
|
||||
}
|
||||
|
||||
void insert(lru_cache_key_t key, lru_cache_data_t data)
|
||||
{
|
||||
gotoxy(col, row);
|
||||
printf("Add %04x:%04x", key, data);
|
||||
|
||||
gotoxy(0, 0);
|
||||
printf("add: %04x:%04x ", key, data);
|
||||
lru_cache_insert(key, data);
|
||||
|
||||
display();
|
||||
}
|
||||
|
||||
void delete (lru_cache_key_t key)
|
||||
{
|
||||
gotoxy(col, row);
|
||||
printf("Del %04x", key);
|
||||
|
||||
gotoxy(0, 0);
|
||||
printf("del: %04x ", key);
|
||||
lru_cache_delete(key);
|
||||
|
||||
display();
|
||||
}
|
||||
|
||||
|
@ -85,20 +58,19 @@ void main()
|
|||
{
|
||||
lru_cache_init();
|
||||
|
||||
bgcolor(BROWN);
|
||||
textcolor(WHITE);
|
||||
clrscr();
|
||||
scroll(0);
|
||||
|
||||
int cache[128];
|
||||
|
||||
char ch = kbhit();
|
||||
// char ch = kbhit();
|
||||
char ch = 0;
|
||||
do {
|
||||
if (lru_cache_is_max()) {
|
||||
lru_cache_key_t last = lru_cache_find_last();
|
||||
delete(last);
|
||||
} else {
|
||||
lru_cache_key_t key = rand() % 0x100;
|
||||
lru_cache_key_t key = rand() % 0x20;
|
||||
lru_cache_data_t data = get(key);
|
||||
if (data != LRU_CACHE_NOTHING) {
|
||||
data += 1;
|
||||
|
@ -111,6 +83,6 @@ void main()
|
|||
insert(key, 0);
|
||||
}
|
||||
}
|
||||
ch = kbhit();
|
||||
// ch = kbhit();
|
||||
} while (ch != 'x');
|
||||
}
|
|
@ -10,16 +10,29 @@
|
|||
*
|
||||
*/
|
||||
|
||||
//#include <conio_var_asm.h>
|
||||
|
||||
// // Register the compilation as an export library output artefact.
|
||||
// // There is no main() function!
|
||||
#pragma asm_library
|
||||
#pragma calling(__varcall)
|
||||
|
||||
#define LRU_CACHE_MAX 96
|
||||
#pragma var_model(zp)
|
||||
|
||||
#pragma asm_export(lru_cache_init)
|
||||
#pragma asm_export(lru_cache_find_last)
|
||||
#pragma asm_export(lru_cache_is_max)
|
||||
#pragma asm_export(lru_cache_index)
|
||||
#pragma asm_export(lru_cache_get)
|
||||
#pragma asm_export(lru_cache_set)
|
||||
#pragma asm_export(lru_cache_data)
|
||||
#pragma asm_export(lru_cache_insert)
|
||||
#pragma asm_export(lru_cache_delete)
|
||||
#pragma asm_export(lru_cache_display)
|
||||
|
||||
#pragma calling(__phicall)
|
||||
|
||||
#define LRU_CACHE_MAX 24
|
||||
#define LRU_CACHE_SIZE 32
|
||||
|
||||
#include <cx16.h>
|
||||
#include "lru-cache.h"
|
||||
#include <conio.h>
|
||||
#include <stdio.h>
|
||||
|
@ -346,15 +359,13 @@ void lru_cache_display(char x, char y) {
|
|||
gotoxy(x, y);
|
||||
|
||||
printf("least recently used cache statistics\n");
|
||||
printf("size = %3u, first = %2x, last = %2x, count = %2x\n\n", LRU_CACHE_SIZE, lru_cache.first, lru_cache.last, lru_cache.count);
|
||||
|
||||
printf("least recently used hash table\n\n");
|
||||
printf("size:%02x, first:%02x, last:%02x, cnt:%2x\n\n", LRU_CACHE_SIZE, lru_cache.first, lru_cache.last, lru_cache.count);
|
||||
|
||||
printf(" ");
|
||||
do {
|
||||
printf(" %02x/%02x ", col, col + 8);
|
||||
printf(" %1x/%1x ", col, col + 8);
|
||||
col++;
|
||||
} while (col < 8);
|
||||
} while (col < 4);
|
||||
printf("\n");
|
||||
|
||||
col = 0;
|
||||
|
@ -371,7 +382,7 @@ void lru_cache_display(char x, char y) {
|
|||
printf(" ----:--");
|
||||
}
|
||||
index++;
|
||||
} while (index < index_row + 8);
|
||||
} while (index < index_row + 4);
|
||||
printf("\n");
|
||||
|
||||
index = index_row;
|
||||
|
@ -380,11 +391,11 @@ void lru_cache_display(char x, char y) {
|
|||
printf(" %02x:", lru_cache.next[index]);
|
||||
printf("%02x ", lru_cache.prev[index]);
|
||||
index++;
|
||||
} while (index < index_row + 8);
|
||||
} while (index < index_row + 4);
|
||||
printf("\n");
|
||||
|
||||
index_row += 8;
|
||||
} while (index_row < 128);
|
||||
index_row += 4;
|
||||
} while (index_row < 4*4*2);
|
||||
|
||||
printf("\n");
|
||||
|
||||
|
@ -394,7 +405,7 @@ void lru_cache_display(char x, char y) {
|
|||
lru_cache_index_t count = 0;
|
||||
col = 0;
|
||||
|
||||
while (count < lru_cache.size) {
|
||||
while (count < 6) {
|
||||
if (count < lru_cache.count)
|
||||
printf(" %4x", lru_cache.key[index]);
|
||||
else
|
|
@ -1,29 +0,0 @@
|
|||
|
||||
// Create an .asm library of imporant conio functions.
|
||||
// Export to conio_var.asm
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
#pragma var_model(zp)
|
||||
|
||||
// Declare this compilation to generate the conio_var_asm file!
|
||||
#pragma asm_library("conio_var")
|
||||
|
||||
// Declare the procedures to be exported to the .asm libary with the indicated calling convention.
|
||||
#pragma asm_export("conio_var", __varcall, __conio_var_start, conio_x16_init)
|
||||
#pragma asm_export("conio_var", __varcall, clrscr)
|
||||
#pragma asm_export("conio_var", __varcall, gotoxy)
|
||||
#pragma asm_export("conio_var", __varcall, wherex, wherey)
|
||||
#pragma asm_export("conio_var", __varcall, screensize, screensizex, screensizey, cputln )
|
||||
#pragma asm_export("conio_var", __stackcall, cputc )
|
||||
#pragma asm_export("conio_var", __varcall, cputcxy, cputs, cputsxy, textcolor, bgcolor, bordercolor )
|
||||
#pragma asm_export("conio_var", __varcall, kbhit, cursor, scroll )
|
||||
#pragma asm_export("conio_var", __varcall, screenlayer1, screenlayer2)
|
||||
#pragma asm_export("conio_var", __varcall, cpeekc, cpeekcxy)
|
||||
|
||||
|
||||
// For the moment, allocate local procedure variables to memory.
|
||||
#pragma var_model(local_mem)
|
||||
|
||||
#include <conio.h>
|
||||
//#include <cx16-conio.h>
|
||||
|
|
@ -8,7 +8,6 @@
|
|||
cross procedure there is overlap of ZP, so that the least zeropage is consumed by the library.
|
||||
Nested functions should have been taken into consideration during ZP allocation, and there
|
||||
should be no overlap of nested function parameters.
|
||||
|
||||
*/
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
|
@ -16,13 +15,11 @@
|
|||
|
||||
// Register the compilation as an calc.asm export library output artefact.
|
||||
// There is no main() function!
|
||||
#pragma asm_library("calc")
|
||||
|
||||
// For the moment, allocated local procedure variables to memory.
|
||||
#pragma var_model(local_mem)
|
||||
#pragma asm_library
|
||||
|
||||
// Register the exported procedures that should be included in the calc.asm export library.
|
||||
#pragma asm_export("calc", __varcall, plus, min)
|
||||
#pragma calling(__varcall)
|
||||
#pragma asm_export(plus, min)
|
||||
|
||||
// The plus function.
|
||||
char plus(char a, char b) {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
cross procedure there is overlap of ZP, so that the least zeropage is consumed by the library.
|
||||
Nested functions should have been taken into consideration during ZP allocation, and there
|
||||
should be no overlap of nested function parameters.
|
||||
|
||||
*/
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
|
@ -16,13 +15,14 @@
|
|||
|
||||
// Register the compilation as an calc.asm export library output artefact.
|
||||
// There is no main() function!
|
||||
#pragma asm_library("calc")
|
||||
#pragma asm_library
|
||||
|
||||
// For the moment, allocated local procedure variables to memory.
|
||||
#pragma var_model(local_mem)
|
||||
|
||||
// Register the exported procedures that should be included in the calc.asm export library.
|
||||
#pragma asm_export("calc", __varcall, plus, min)
|
||||
#pragma calling(__varcall)
|
||||
#pragma asm_export(plus, min)
|
||||
|
||||
// The plus function.
|
||||
char plus(char a, char b) {
|
||||
|
|
|
@ -16,13 +16,10 @@
|
|||
|
||||
// Register the compilation as an calc.asm export library output artefact.
|
||||
// There is no main() function!
|
||||
#pragma asm_library("calc")
|
||||
|
||||
// For the moment, allocated local procedure variables to memory.
|
||||
#pragma var_model(local_mem)
|
||||
#pragma asm_library
|
||||
|
||||
// Register the exported procedures that should be included in the calc.asm export library.
|
||||
#pragma asm_export("calc", __varcall, plus, min, plus_min)
|
||||
#pragma asm_export(plus_min)
|
||||
|
||||
// The plus function.
|
||||
char plus(char a, char b) {
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/* Compile with C64
|
||||
|
||||
Here we use the calc.asm library functions.
|
||||
We also use the printf to nicely display the result and to document how the
|
||||
imported calc.asm library works and how it compiles with the main source.
|
||||
*/
|
||||
|
||||
#pragma encoding(screencode_mixed)
|
||||
#pragma var_model(zp)
|
||||
|
||||
// We include the calc_asm.h generated C function prototype file.
|
||||
// This file contains the function prototypes for plus and min, which are
|
||||
// contained in the calc.asm file in assembler.
|
||||
// #include "calc_asm.h"
|
||||
|
||||
// We include the C64 and printf stuff.
|
||||
|
||||
__export char r;
|
||||
|
||||
// The plus function.
|
||||
char plus(char a, char b) {
|
||||
return a+b;
|
||||
}
|
||||
|
||||
// The min function.
|
||||
char min(char a, char b) {
|
||||
return a-b;
|
||||
}
|
||||
|
||||
char plus_min(char a, char p, char m) {
|
||||
char pr = plus(a,p);
|
||||
char mr = min(pr,m);
|
||||
return mr;
|
||||
}
|
||||
|
||||
char* x = (char*)(0x400);
|
||||
char* y = (char*)(0x401);
|
||||
char* z = (char*)(0x402);
|
||||
|
||||
// Note that both functions stand on its own in this source, there is no main!
|
||||
// Parameters a and b are taken into consideration when allocating the ZP!
|
||||
|
||||
void main() {
|
||||
*x = 5;
|
||||
*y = 4;
|
||||
*z = 1;
|
||||
r = plus_min(*x,*y,*z);
|
||||
r = plus_min(r,*y,*z);
|
||||
// r = plus_min(5,4,1);
|
||||
// r = plus_min(r,4,1);
|
||||
}
|
|
@ -19,7 +19,8 @@
|
|||
#pragma asm_library
|
||||
|
||||
// Register the exported procedures that should be included in the calc.asm export library.
|
||||
#pragma asm_export("calc", __varcall, plus, min, plus_min)
|
||||
#pragma calling(__varcall)
|
||||
#pragma asm_export(plus_min)
|
||||
|
||||
// The plus function.
|
||||
char plus(char a, char b) {
|
||||
|
|
|
@ -19,9 +19,6 @@
|
|||
#pragma asm_library
|
||||
#pragma calling(__varcall)
|
||||
|
||||
// For the moment, allocated local procedure variables to memory.
|
||||
#pragma var_model(local_mem)
|
||||
|
||||
// The plus functions
|
||||
|
||||
char plus1(char d) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user