Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [rom/] [pagealloc.asm] - Blame information for rev 384

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 177 winston
;The MIT License
2
;
3
;Copyright (c) 2008 Dylan Smith
4
;
5
;Permission is hereby granted, free of charge, to any person obtaining a copy
6
;of this software and associated documentation files (the "Software"), to deal
7
;in the Software without restriction, including without limitation the rights
8
;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
;copies of the Software, and to permit persons to whom the Software is
10
;furnished to do so, subject to the following conditions:
11
;
12
;The above copyright notice and this permission notice shall be included in
13
;all copies or substantial portions of the Software.
14
;
15
;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
;THE SOFTWARE.
22
 
23
; Page allocation routines, that allows code (mostly ROM modules) to reserve
24
; a page of static RAM in some kind of orderly way.
25
;
26
; The last 6 pages of RAM are used for temporary workspace and can't be
27
; reserved. (Anyone can use them, though, but another module or program
28
; can also write there). The first page (0xC0) is permanently mapped to
29
; 0x3000-0x3FFF and can't be reserved either.
30
;
31
; The rest of RAM should only be used after being reserved to ensure that
32
; you don't trample on the workspace of a ROM module. Reservation routines
33
; are here and work on the level of 1 page (4K).
34 384 winston
.include        "sysvars.inc"
35
.include        "sysdefs.inc"
36 177 winston
 
37
;---------------------------------------------------------------------------
38
; F_reservepage
39
; Reserves a page. On entry, pass the ROM ID that is making the request in A.
40
; Pass 0xFF if it's just a general program, and not a module.
41
; On return, A contains the page reserved. If no pages are free the carry
42
; flag is set.
43 384 winston
.text
44
.globl F_reservepage
45
F_reservepage:
46 177 winston
        ld b, 25                ; number of RAM pages that can be reserved
47
        ld hl, pagealloc        ; search the page allocation table for a page
48
        ex af, af'              ; save A
49 384 winston
.searchloop1:
50 177 winston
        ld a, (hl)              ; examine current page
51
        and a                   ; is it zero (unallocated) ?
52 384 winston
        jr z, .pagefound1
53 224 winston
        inc l                   ; advance to the next
54 384 winston
        djnz .searchloop1
55 177 winston
        scf                     ; if we get here no free pages were found.
56
        ret
57 384 winston
.pagefound1:
58 177 winston
        ex af, af'              ; get originally passed value
59
        ld (hl), a              ; mark the page allocated
60
        ld a, l                 ; calculate the page
61
        sub pagealloc % 256     ; by looking at the table position
62 384 winston
        add a, LOWEST_PAGE              ; and adding the lowest possible page
63 177 winston
        ret
64
 
65
;--------------------------------------------------------------------------
66
; F_freepage
67
; Frees a page. Pass the page number in A.
68 384 winston
.globl F_freepage
69
F_freepage:
70 177 winston
        ld hl, pagealloc
71
        sub LOWEST_PAGE         ; find offset in table
72
        add a, l                ; add table base address
73
        ld l, a                 ; now hl points to it
74
        ld (hl), 0              ; clear it
75
        ret