home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Crawly Crypt Collection 1
/
crawlyvol1.bin
/
program
/
compiler
/
nasm20b
/
nasm_src
/
lib
/
src
/
coderel.s65
< prev
next >
Wrap
Text File
|
1993-01-19
|
5KB
|
208 lines
DPOKE :vre,|RELTAB-1
sec
; carry must be set for :loop
:loop ldy #3 ; copy reloc
:l1 lda (:vre),y ; dir. in..
sta :mod-1,y
dey
bne :l1
lda :vre ; update :L1
adc #2 ; pointer to the reloc table (+ Carry)
sta :vre ; INC INC might
bcc :_foo ; be shorter
inc :vre+1
clc
:_foo lda :siz
adc :src
sta :siz
lda :siz+1
adc :src+1
sta :siz+1
lda :mod ; what to reloc
bmi :found ; EOP reached!!
beq :inst ; instructions ->
cmp #2 ; relocatable
bcs :data ; data ->
:l2 lda (:src),y ; Xfer 1 byte
sta (:dst),y ; slowly...
lda #1 ; add one to
jsr :chk ; pts and check
bcc :l2 ; ok one more
bcs :loop ; new segment
;
:inst lda (:src),y ; get instr
sta (:dst),y
and # $F ; examine l.sign
tax ; nybble
lda :lsbtab,x ; known val. ?
bpl :ez ; yep ->
jsr :lookdeep ; special case
:ez tax ; save #bytes
cmp #2 ; need to reloc
bcc :dochk ; no ->
beq :twobyte ; no ->
iny
jsr :xreloc ; maybe ...
dey
jmp :dochk
:found jmp (|MEMLO)
:twobyte iny
lda (:src),y
sta (:dst),y
dey
:dochk txa
jsr :chk
bcc :inst ; ok one more
bcs :loop
:data cmp #3 ; DBYTE ?
beq :dbytes
bcs :eofmove ; -able code
:ldata sec
jsr :xreloc
lda #2
jsr :chk
bcc :ldata
bcs :loop
:dbytes iny
sec
lda (:src),y ; do the
sbc :dif ; same (no SEC)
sta (:dst),y ; here ofcourse
dey
lda (:src),y
sbc :dif+1
sta (:dst),y
lda #2
jsr :chk
bcc :dbytes
jmp :loop
; ------------------------------
; And handle the special cases
; too.
; ------------------------------
:lookdeep lda (:src),y
lsr a
lsr a
lsr a
lsr a
cpx #9
beq :e1o2
;
cmp #8
bcc :e1o2o3
lda #2
rts
;
:e1o2 and #1
adc #1
rts
;
:e1o2o3 tax
lda :msbtab,x
rts
; -------------------------------
; This isn't absolutely clear yet
; -------------------------------
:lsbtab .byte 128,2,2,2,2,2,2,2
.byte 1,128,1,3,3,3,3,3
;
:msbtab .byte 1,2,3,2,1,2,1,2
.byte 2,2,2,2,2,2,2,2
; -------------------------------
; If we encountered the STOP
; moving code bit we keep on
; relocating. but set :SRC ==
; :DST!. Can do that only ONCE
; -------------------------------
:eofmove DMOVE :src,:dst
jmp :loop
; -------------------------------------------------------------
; Actual relocating action. Rite here before your eyes. No I am
; not in a Speed Demon mood this evening. Therefore another
; nice memory saving subroutine. Test whether the address is in
; the relocatable range.
; Carry must be set.
; -------------------------------------------------------------
:xreloc lda (:src),y ; See them
sbc #<|R_START-1 ; the try
iny ; to bring
lda (:src),y ; the hammer down
sbc #>|R_START-1 ; no damn
bcc :toolow ; chains can
dey
lda #<|R_END ; hold me to
sbc (:src),y ; the ground
lda #>|R_END
iny
sbc (:src),y
bcc :toolow ; too HI!
dey ; one up
lda (:src),y ; do the
sbc :dif ; same (no SEC)
sta (:dst),y
iny
lda (:src),y
sbc :dif+1
sta (:dst),y ; here ofcourse
dey
rts
:toolow lda (:src),y ; copy 2
sta (:dst),y ; w/o reloc
dey ; maybe a CHIP
lda (:src),y ; access or
sta (:dst),y ; a call to
rts ; OS
iny
lda (:src),y ; do the
sbc :dif+1 ; same (no SEC)
sta (:dst),y ; here ofcourse
dey
lda (:src),y
sbc :dif
sta (:dst),y
; ------------------------------
; CHK look whether we're leaving
; a segment. (e.g. DATA->INSTR)
; and update pointer according
; to the value in A
; ------------------------------
:chk tax
clc
adc :src
sta :src
bcc :ok
inc :src+1
clc
:ok txa
adc :dst
sta :dst
bcc :ok2
inc :dst+1
:ok2 lda :src+1 ; src+1 < siz+1
cmp :siz+1
bne :not_yet ; yes -> carry clear : continue
lda :src ; src < siz
cmp :siz ; carry clear : yes, continue
:not_yet rts