Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [modules/] [snapman/] [memory.asm] - Blame information for rev 372

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 280 winston
;The MIT License
2
;
3
;Copyright (c) 2009 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 372 winston
.include        "spectranet.inc"
23
.include        "sysvars.inc"
24 280 winston
 
25
;-------------------------------------------------------------------------
26
; F_init: Initialize the snapshot manager.
27 372 winston
.globl F_init
28
F_init:
29 280 winston
        call F_allocpage
30 372 winston
        jr c,  .failed1
31 280 winston
        ld hl, STR_initialized
32
        call PRINT42
33
        ret
34 372 winston
.failed1:
35 280 winston
        ld hl, STR_failed
36
        call PRINT42
37
        ret
38
 
39
; Claim our memory page, functions to fetch etc.
40
; Note: Ought to be a library function.
41
 
42 372 winston
.globl F_allocpage
43
F_allocpage:
44 280 winston
        ld a, (v_pgb)           ; Find our identity
45
        call RESERVEPAGE
46
        ret c                   ; Failed to reserve a page!
47
        ld b, a                 ; Save the returned page number
48
        ld a, (v_pgb)           ; Multiply our page number by 8
49
        rlca                    ; which gets our index in the fixed
50
        rlca                    ; sysvars in 0x3900
51
        rlca
52
        ld h, 0x39              ; set the MSB
53
        ld l, a                 ; and the LSB
54
        ld (hl), b              ; then save the page we got
55
        inc l                   ; point at next byte
56
        ld a, (v_pga)
57
        ld (hl), a              ; save current page A
58
        ld a, b                 ; and page in the new page
59
        call SETPAGEA
60
 
61
        ld hl, 0x1000           ; clear the memory
62
        ld de, 0x1001
63
        ld bc, 0xFFF
64
        ld (hl), l
65
        ldir
66
 
67
        xor a
68
        ret
69
 
70
;-----------------------------------------------------------------------------
71
; F_fetchpage
72
; Gets our page of RAM and puts it in page area A.
73 372 winston
.globl F_fetchpage
74
F_fetchpage:
75 280 winston
        push af
76
        push hl
77
        ld a, (v_pgb)           ; get our ROM number and calculate
78
        rlca                    ; the offset in sysvars
79
        rlca
80
        rlca
81
        ld h, 0x39              ; address in HL
82
        ld l, a
83
        ld a, (hl)              ; fetch the page number
84
        and a                   ; make sure it's nonzero
85 372 winston
        jr z,  .nopage3
86 280 winston
        inc l                   ; point hl at "page number storage"
87
        ex af, af'
88
        ld a, (v_pga)
89
        ld (hl), a              ; store current page A
90
        ex af, af'
91
        call SETPAGEA           ; Set page A to the selected page
92
        pop hl
93
        pop af
94
        or a                    ; ensure carry is cleared
95
        ret
96 372 winston
.nopage3:
97 280 winston
        pop hl                  ; restore the stack
98
        pop af
99
        ld a, 0xFF              ; TODO: ENOMEM return code
100
        scf
101
        ret
102
 
103
;---------------------------------------------------------------------------
104
; F_isallocated
105
; Tests to see if we have a memory page allocated already.
106
; Returns nonzero if we have a page
107 372 winston
.globl F_isallocated
108
F_isallocated:
109 280 winston
        push hl
110
        ld a, (v_pgb)           ; get our ROM number
111
        rlca                    ; multiply by 8 to find our
112
        rlca                    ; fixed sysvars area
113
        rlca
114
        ld h, 0x39              ; MSB
115
        ld l, a                 ; LSB
116
        ld a, (hl)              ; Get the hypothetical page number
117
        and a                   ; Test for zero
118
        pop hl
119
        ret
120
 
121
;---------------------------------------------------------------------------
122
; F_restorepage
123
; Restores page A to its original value.
124 372 winston
.globl F_leave
125
F_leave:
126
.globl F_restorepage
127
F_restorepage:
128 280 winston
        push af
129
        push hl
130
        ld a, (v_pgb)           ; calculate the offset...
131
        rlca
132
        rlca
133
        rlca
134
        inc a                   ; +1
135
        ld h, 0x39
136
        ld l, a
137
        ld a, (hl)              ; fetch original page
138
        call SETPAGEA           ; and restore it
139
        pop hl
140
        pop af
141
        ret
142