Linker/pass1.asm

1 line
16 KiB
NASM
Raw Normal View History

keep obj/pass1 mcopy pass1.mac **************************************************************** * * Pass 1 * * This module contains the subroutines used to do pass 1 * processing of the input files. * **************************************************************** copy directPage **************************************************************** * * Align - align the code to a byte boundary * * Inputs: * sp - pointer to the opcode * pc - current program counter * * Outputs: * sp - pointer to the next opcode * pc - new program counter * **************************************************************** * Align private ldy #1 get the alignment factor lda [sp],Y sta r0 iny iny lda [sp],Y sta r2 add4 sp,#5 jsr PrepareAlign do pass 1 prep for the align rts end **************************************************************** * * Const - constant bytes * * Inputs: * sp - pointer to the opcode * pc - current program counter * * Outputs: * sp - pointer to the next opcode * pc - new program counter * **************************************************************** * Const private lda [sp] and #$00FF tax clc adc pc sta pc bcc lb1 inc pc+2 lb1 txa sec adc sp sta sp bcc lb2 inc sp+2 lb2 rts end **************************************************************** * * DefineSegment - put the segment in the symbol table * * Inputs: * segName - pointer to the segment name * segType - segment type * pc - current pc * segEntry - disp to segment entry point * **************************************************************** * DefineSegment private using Common ph4 segName push the symbol name ptr ph2 #0 length attribute is 0 ph2 #'N' push the type attribute lda segType push the private flag and #$4000 beq lb1 lda #1 lb1 pha ph2 #1 the symbol is global ph2 #0 the symbol is not an expression clc push the location lda pc adc segEntry tax lda pc+2 adc segEntry+2 pha phx lda segType push the data area flag and #$007F cmp #1 beq lb2 ph2 #0 bra lb3 lb2 ph2 #1 lb3 ph2 #1 push the segment flag jsr Define define the symbol rts end **************************************************************** * * DoOrg - set the program counter * * Inputs: * sp - pointer to the opcode * pc - current program counter * * Outputs: * sp - pointer to the next opcode * pc - new program counter * **************************************************************** * DoOrg private using OutCommon ldy #1 get the value and skip the record lda [sp],Y sta r0 ldy #3 lda [sp],Y sta r2+2 add4 sp,#5 sub4 r0,loadOrg get the disp from the segment start cmpl pc,r0 bge lb1 if the disp is greater than the pc then move4 r0,pc update the pc lb1 anop rts end **************************************************************** * * DoPass1 - Do pass 1 processing * * Outputs: * C - set if an error occurred * **************************************************************** * DoPass1 start using Common ; ; Write the pass header ; lda #1 pass = 1 sta pass lda list if list then beq wp1 puts #'Segment:',cr=t print the general header putcr bra wp2 else if progress then wp1 lda progress beq wp2 puts #'Pass 1: ' print the dot header wp2 anop ; ; Initialize pass dependent variables ; jsr InitPass ; ; Process segments until there are no more ; ps1 jsr NextSegment get the next segment bcc rt1 branch if there are no more jsr DefineSegment put the segment in the symbol table jsr ListSeg list the segname start info jsr DoSegment process this segment add4 pc,segSpace add in the reserved space (if any) bra ps1 next segment ; ; Return to main ; rt1 lda list if list or progress then bne rt2 lda progress beq rt3 rt2 putcr write a cr rt3 anop endif clc rts end **************************************************************** * * DoSegment - process the opcodes in this segment * * Inputs: * sp - pointer to the first opcode to process * **************************************************************** * DoSegment private lb1 lda [sp] and #$00FF asl A tax jsr (addr,X) bra lb1 addr dc a'End'