1; 2; Ullrich von Bassewitz, 2002-11-29 3; 4; Common functions of the extended memory API. 5; 6 7 .import return0, em_libref 8 .importzp ptr1 9 10 .include "em-kernel.inc" 11 .include "em-error.inc" 12 13 14;---------------------------------------------------------------------------- 15; Variables 16 17 18.bss 19_em_drv: .res 2 ; Pointer to driver 20 21; Jump table for the driver functions. 22.data 23emd_vectors: 24emd_install: jmp return0 25emd_uninstall: jmp return0 26emd_pagecount: jmp return0 27emd_map: jmp return0 28emd_use: jmp return0 29emd_commit: jmp return0 30emd_copyfrom: jmp return0 31emd_copyto: jmp return0 32 33; Driver header signature 34.rodata 35emd_sig: .byte $65, $6d, $64, EMD_API_VERSION ; "emd", version 36 37 38;---------------------------------------------------------------------------- 39; unsigned char __fastcall__ em_install (void* driver); 40; /* Install the driver once it is loaded */ 41 42 43_em_install: 44 sta _em_drv 45 sta ptr1 46 stx _em_drv+1 47 stx ptr1+1 48 49; Check the driver signature 50 51 ldy #.sizeof(emd_sig)-1 52@L0: lda (ptr1),y 53 cmp emd_sig,y 54 bne inv_drv 55 dey 56 bpl @L0 57 58; Set the library reference 59 60 ldy #EMD_HDR::LIBREF 61 lda #<em_libref 62 sta (ptr1),y 63 iny 64 lda #>em_libref 65 sta (ptr1),y 66 67; Copy the jump vectors 68 69 ldy #EMD_HDR::JUMPTAB 70 ldx #0 71@L1: inx ; Skip the JMP opcode 72 jsr copy ; Copy one byte 73 jsr copy ; Copy one byte 74 cpy #(EMD_HDR::JUMPTAB + .sizeof(EMD_HDR::JUMPTAB)) 75 bne @L1 76 77 jmp emd_install ; Call driver install routine 78 79; Driver signature invalid 80 81inv_drv: 82 lda #EM_ERR_INV_DRIVER 83 ldx #0 84 rts 85 86; Copy one byte from the jump vectors 87 88copy: lda (ptr1),y 89 sta emd_vectors,x 90 iny 91 inx 92 rts 93 94;---------------------------------------------------------------------------- 95; unsigned char em_uninstall (void); 96; /* Uninstall the currently loaded driver and return an error code. 97; ** Note: This call does not free allocated memory. 98; */ 99 100_em_uninstall: 101 jsr emd_uninstall ; Call driver routine 102 103em_clear_ptr: ; External entry point 104 lda #0 105 sta _em_drv 106 sta _em_drv+1 ; Clear the driver pointer 107 108 tax 109 rts ; Return zero 110