tiles are not packed again
[enJine.git] / main.zas
bloba68f8165bc94c3b3907b6ba749c8efb525723fb3
1 SCR_PART_OFS equ 0
2 HELI_PUT_OR equ 1
4   deffmt runtap
6   org  #6000
7 myfirstbyte:
9   jp   firstTimeInit
11 mainEntry:
12   ;ld   hl,map00
13   ;ld   de,mapData
14   ;call deexo
16   ;ld   hl,tilesBase00
17   ;ld   de,shiftedTilesBuf
18   ;call deexo
19   call prepareShiftedTiles
21   ld   hl,#4000
22   ld   de,#4001
23   ld   bc,6143
24   ld   (hl),0
25   ldir
27   call prepareAttrs
29   ld   hl,0
30   ld   de,#4000+4096
31   ld   b,6
32 .rndFillLoopLine:
33   push bc
34 .rndFillLoop:
35   push de
36   ld   bc,32
37   ldir
38   pop  de
39   inc  d
40   ld   a,d
41   and  #07
42   jr   nz,.rndFillLoop
43   ld   a,e
44   sub  #E0
45   ld   e,a
46   sbc  a,a
47   and  #F8
48   add  a,d
49   ld   d,a
50   pop  bc
51   djnz .rndFillLoopLine
53   ld   hl,#5800+22*32+3
54   ld   de,#5800+22*32+4
55   ld   bc,26
56   ld   (hl),0107
57   ldir
58   ld   hl,#5800+23*32+3
59   ld   de,#5800+23*32+4
60   ld   bc,26
61   ld   (hl),7
62   ldir
65   ld   hl,IntrHandlerSmall
66   ld   (#FFF5),hl
68   call buildPushers
70 MainLoop:
71   ei
72   nop
73   halt
75  IF 0
76   ld   hl,#4000
77   call blitHeliAt
78  ENDIF
80   call buildPushers
81   ;ld   hl,14000
82   ;call delay
83   call hsync
84   di   ; sadly, we can skip one intr here
85   call blitMap
86   ; here we have ~14000 tstates to put sprites
87   ; one heli: ~1910 ticks with PUT; ~2710 ticks with OR
88   ld   hl,#40EE
89 mainHeliBlidSubr: equ $+1
90   call blitHeliAt
92   ld   hl,#4000
93   call blitHeliAt
94   ld   hl,#4008
95   call blitHeliAt
96   ld   hl,#4010
97   call blitHeliAt
98   ld   hl,#4018
99   call blitHeliAt
100   ;
101   ld   a,(heliPhase)
102   xor  #01
103   ld   (heliPhase),a
104   ;
105   call buildPushers
106   ;
107 .waitformove:
108   call WinStick.readMoves
109   jr   nz,.somethingpressed
110 .goonml:
111   ei
112   ;nop
113   ;halt
114   ld   hl,10000
115   call delay
116   jr   MainLoop
118 .somethingpressed:
119   ; C,A: state (LRUDF; F is #01)
120   xor  a
121   bit  4,c
122   jr   z,.notleft
123   ld   a,(plrXOffset)
124   sub  a,1
125   jr   nc,.leftok
126   ld   a,(mapX)
127   dec  a
128   and  #3f
129   ld   (mapX),a
130   ld   a,7
131 .leftok:
132   ld   (plrXOffset),a
133   ld   a,(leftCnt)
134   inc  a
135   jr   nz,.notleft
136   ld   a,250
137 .notleft:
138   ld   (leftCnt),a
140   xor  a
141   bit  3,c
142   jr   z,.notright
143   ld   a,(plrXOffset)
144   inc  a
145   and  #07
146   jr   nz,.rightok
147   ld   a,(mapX)
148   inc  a
149   and  #3f
150   ld   (mapX),a
151   xor  a
152 .rightok:
153   ld   (plrXOffset),a
154   ld   a,(rightCnt)
155   inc  a
156   jr   nz,.notright
157   ld   a,2
158 .notright:
159   ld   (rightCnt),a
161   bit  2,c
162   jr   z,.notup
163   ld   a,(plrYOffset)
164   sub  a,1
165   jr   nc,.upok
166   ld   a,(mapY)
167   dec  a
168   and  #3f
169   ld   (mapY),a
170   ld   a,7
171 .upok:
172   ld   (plrYOffset),a
173 .notup:
175   bit  1,c
176   jr   z,.notdown
177   ld   a,(plrYOffset)
178   inc  a
179   and  #07
180   jr   nz,.downok
181   ld   a,(mapY)
182   inc  a
183   and  #3f
184   ld   (mapY),a
185   xor  a
186 .downok:
187   ld   (plrYOffset),a
188 .notdown:
190   ; check direction
191   ld   hl,(leftCnt)
192   ld   a,h
193   or   a
194   jr   z,.notLeftDir
195   ld   hl,blitHeliAt1
196   sub  a,4
197   jr   c,.dirsDone
198   ld   hl,blitHeliAt2
199   jr   .dirsDone
201 .notLeftDir:
202   ld   a,l
203   or   a
204   jr   z,.notRightDir
206 .notRightDir:
207   ld   hl,blitHeliAt
209 .dirsDone:
210   ld   (mainHeliBlidSubr),hl
212   jp   .goonml
215 hsync:
216   in   a,(#ff)
217   cp   6
218   jr   nz,hsync
219   ret
221 prepareAttrs:
222   ld   hl,#5800
223   ld   de,#5801
224   ld   bc,767
225   ld   (hl),0
226   ldir
227   ld   hl,#5800+3
228   ld   b,16
229   ld   a,6
230 .fillit:
231   push bc
232   ld   (.filladdr),hl
233 .filladdr: equ $+1
234   ld   de,0
235   inc  de
236   ld   bc,26
237   ld   (hl),a
238   ldir
239   ld   hl,(.filladdr)
240   ld   de,32
241   add  hl,de
242   pop  bc
243   djnz .fillit
244   cp   a,6
245   ret  nz
246   ld   a,1
247   ld   b,8
248   jr   .fillit
249   ;ret
251 leftCnt: db 0
252 rightCnt: db 0
254   include <winstick>
255   include "delay.zas"
258 IntrHandler:
259 IntrHandlerSmall:
260   ei
261   ret
263   defb "JOFFA!"
265 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
266 ;; build shifted tiles
268 prepareShiftedTiles:
269   IF 1
270     ; tiles are not packed
271     ld   de,shiftedTilesBuf
272     push de
273     ; first: unshifted
274     ld   hl,tilesBase
275     ld   bc,6*16*4
276     ldir
277     pop  hl
278   ELSE
279     ; tiles are packed
280     ld   hl,shiftedTilesBuf
281     ld   de,shiftedTilesBuf+6*16*4
282   ENDIF
283   ;
284   ld   a,3  ; 3 shifts left
285 .shiftNextSet:
286   ex   af,af'
287   ; HL: addr of previous tileset
288   ; DE: addr of current tileset
289   push de
290   push de
291   ld   bc,6*16*4
292   ldir
293   ; previous tiles copied, now shift
294   pop  hl      ; start of the current block
295   ld   c,16*4  ; lines
296 .shiftNextLine:
297   ld   e,b     ; B is always 0 here
298   ld   b,6
299 .shiftNextByte:
300   ld   a,(hl)
301   ld   d,a
302   rr   e
303   rra
304   rr   e
305   rra
306   ld   (hl),a
307   inc  hl
308   ld   e,d
309   djnz .shiftNextByte
310   dec  c
311   jr   nz,.shiftNextLine
312   ex   de,hl  ; now DE is the new dest address
313   pop  hl     ; current set address
314   ex   af,af'
315   dec  a
316   jr   nz,.shiftNextSet
317   ret
319 exo_mapbasebits: equ #4000  ; 156 bytes
320   include <deexo.inc>
322 tilesBase:
323   include "ffsp.zas"
324 ;tilesBase00:
325 ;  incbin "bdata/tiles_blobs.exo"
327 ;map00:
328   ;incbin "bdata/map00.exo"
331 mapData: equ #8000
332 mapSize: equ #0800
334   org  mapData
335   ;incbin "maps/map00.bin"
336   incbin "maps/work.bin"
338   org  #8800
339 pusherStart: equ $  ; #8800
340                     ; max pusher end will be: #8eff
342   org  #8f00
343 scrRowsTable: ds 128*2
345   ; #9000
346 shiftedTilesBuf: ds 16*4*6*4
347   ; #9600
348   DISPHEX "shiftedTilesBuf: start=#", shiftedTilesBuf, "; end=#", $, "\n"
350 tileBlockOffsets:
351   dw shiftedTilesBuf+0*6*16
352   dw shiftedTilesBuf+1*6*16
353   dw shiftedTilesBuf+2*6*16
354   dw shiftedTilesBuf+3*6*16
356 ;0  1  2  3
357 ;bc de af hl
358 pushCodes:
359   db 0E5h,0E5h  ; 0 : push hl, push hl : 33
360   db 0D5h,0C5h  ; 1 : push de, push bc : 01
361   db 0D5h,0D5h  ; 2 : push de, push de : 11
362   db 0F5h,0D5h  ; 3 : push af, push de : 12
363   db 0C5h,0E5h  ; 4 : push bc, push hl : 30
364   db 0E5h,0F5h  ; 5 : push hl, push af : 23
365   db 0F5h,0C5h  ; 6 : push af, push bc : 02
366   db 0E5h,0C5h  ; 7 : push hl, push bc : 03
367   db 0F5h,0E5h  ; 8 : push af, push hl : 32
368   db 0F5h,0F5h  ; 9 : push af, push af : 22
369   db 0C5h,0C5h  ;10 : push bc, push bc : 00
370   db 0D5h,0F5h  ;11 : push de, push af : 21
371   db 0C5h,0D5h  ;12 : push bc, push de : 10
372   db 0E5h,0D5h  ;13 : push hl, push de : 13
373   db 0D5h,0E5h  ;14 : push de, push hl : 31
374   db 0C5h,0F5h  ;15 : push bc, push af : 20
376 ; jump table for screen pushers
377 ; addr, tilesofs, 2ndtilesofs
378 pusherJumpTable:
379   ds 3*2*9
381 shiftedTilesOfsTable:
382   dw  3*6*16*4
383   dw  2*6*16*4
384   dw  1*6*16*4
385   dw  0*6*16*4
388 plrXOffset: db 0  ; player X offset in the tile (0-7): in 2 pixels
389 plrYOffset: db 0  ; player Y offset in the tile (0-28; step: 4); (0-7): in 2 pixels
390 mapX: db 0
391 mapY: db 0
393 savedSP: dw 0
394 relGfxSavedSP: dw 0
396   defm "JOFFA!"
398 heliPhase: db 0
400   include "hspr.zas"
401   DISPHEX "hspr: start=#", heliframe00, "; end=#", $, "\n"
403 blitHeliAt:
404   ld   (savedSP),sp
405   ld   sp,heliframe00
406   ld   a,(heliPhase)
407   or   a
408   jp   nz,hf0ok
409   ld   sp,heliframe01
410   jp   hf0ok
412 blitHeliAt1:
413   ld   (savedSP),sp
414   ld   sp,heliframe10
415   ld   a,(heliPhase)
416   or   a
417   jp   nz,hf0ok
418   ld   sp,heliframe11
419   jp   hf0ok
421 blitHeliAt2:
422   ld   (savedSP),sp
423   ld   sp,heliframe20
424   ld   a,(heliPhase)
425   or   a
426   jp   nz,hf0ok
427   ld   sp,heliframe21
428 @hf0ok:
430   ld   b,18/2
431 .loop0:
432   ; left-to-right stripe
433   DUP 2
434   pop  de
435  IFX HELI_PUT_OR
436   ld   a,e
437   or   (hl)
438   ld   (hl),a
439  ELSE
440   ld   (hl),e
441  ENDIF
442   inc  l
443  IFX HELI_PUT_OR
444   ld   a,d
445   or   (hl)
446   ld   (hl),a
447  ELSE
448   ld   (hl),d
449  ENDIF
450   inc  l
451   EDUP
452   org  $-1  ; overwrite last 'inc l'
453   ; right-to-left stripe
454   inc  h
455   ld   a,h
456   and  #07
457   jp   nz,.blh_dshort0
458   ld   a,l
459   sub  #E0
460   ld   l,a
461   sbc  a,a
462   and  #F8
463   add  a,h
464   ld   h,a
465 .blh_dshort0:
467   DUP 2
468   pop  de
469  IFX HELI_PUT_OR
470   ld   a,e
471   or   (hl)
472   ld   (hl),a
473  ELSE
474   ld   (hl),e
475  ENDIF
476   dec  l
477  IFX HELI_PUT_OR
478   ld   a,d
479   or   (hl)
480   ld   (hl),a
481  ELSE
482   ld   (hl),d
483  ENDIF
484   dec  l
485   EDUP
486   org  $-1  ; overwrite last 'dec l'
487   inc  h
488   ld   a,h
489   and  #07
490   jp   nz,.blh_dshort1
491   ld   a,l
492   sub  #E0
493   ld   l,a
494   sbc  a,a
495   and  #F8
496   add  a,h
497   ld   h,a
498 .blh_dshort1:
499   djnz .loop0
501 .done:
502   ld   sp,(savedSP)
503   ret
504   DISPHEX "blitHeliAt: start=#", blitHeliAt, "; end=#", $, "\n"
507 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
508 ;; blit map onto the screen using prebuild 'pushers'
510 blitMap:
511   xor  a
512   ; A is the index in screen line table
513   ; also it is used as 'stop flag', due
514   ; to the fact that we have to render
515   ; only 2/3 of the screen, which is
516   ; exactly 128 lines
517   ld   l,a
518   ld   h,a
519   ;ld   hl,%0001000100010001
520   ; HL is always 0 for 'pushers'
521   ; we can load it with some 'background' graphix
522   ; for funny fx
523   ; reset Z flag
524   ld   b,a
525   inc  b
526   ex   af,af'  ; switch to 'working' A
527   exx          ; switched to 'loop' register set
528   ld   (savedSP),sp
529   ; calculate number of visible lines in top tile
530   ld   bc,(plrXOffset)
531   ld   a,8
532   sub  b      ; plrYOffset
533   add  a,a
534   ld   (blitMapRowCountVar),a
535   ;
536   ld   a,c    ; plrXOffset
537   cp   4
538   ld   a,2Ch  ; INC L
539   jr   c,$+3
540   xor  a      ; NOP
541   ld   (blitMapShiftCmd),a
542   ; calc tilegfx addr (we have set of shifted tiles)
543   ld   a,c ; stored plrXOffset
544   and  3
545   add  a,a
546   add  a,shiftedTilesOfsTable%256
547   ld   l,a
548   IF sameseg(shiftedTilesOfsTable, shiftedTilesOfsTable+5)
549     ld   h,shiftedTilesOfsTable/256
550     ld   a,(hl)
551     inc  l
552   ELSE
553     ld   a,shiftedTilesOfsTable/256
554     adc  a,0
555     ld   h,a
556     ld   a,(hl)
557     inc  hl
558   ENDIF
559   ld   h,(hl)
560   ld   l,a
561   ld   (blitMapGfxOfs),hl
562   ;
563   ex   de,hl
564   ; DE: tiles offset
565   ld   hl,pusherJumpTable
566   ld   c,(hl)
567   inc  l
568   ld   b,(hl)
569   inc  l
570   ld   (pusherAddress),bc
571   ; load tile gfx offset to IY
572   ld   c,(hl)
573   inc  l
574   ld   b,(hl)
575   inc  l
576   ld   yl,c
577   ld   yh,b
578   ; load 2nd tile gfx offset to IX
579   ld   c,(hl)
580   inc  l
581   ld   b,(hl)
582   inc  l
583   ld   xl,c
584   ld   xh,b
585   ; shift tile gfx addresses according to player Y offset
586   ld   a,(plrYOffset)
587   add  a,a  ; *2
588   ld   c,a
589   add  a,a  ; *4
590   add  a,c  ; *6
591   ld   b,0
592   ld   c,a
593   ex   de,hl
594   add  hl,bc
595   add  hl,bc
596   ex   de,hl
597   ;
598   add  iy,de
599   add  ix,de
600   ;
601   ex   de,hl
602   ; HL: tile gfx base address
603   ; DE: trash
604 blitMapRowCountVar: equ $+1
605   ld   b,0
606   ; start drawing current row
607 blitMapNextLine:
608   ex   af,af'
609   jp   z,blitMapDone
610   ; load screen line address
611   ld   l,a
612   ld   h,scrRowsTable/256
613   ; move to next table item
614   inc  a
615   inc  a
616   ex   af,af'
617   ; load address
618   ld   sp,hl
619   pop  hl
620 blitMapShiftCmd:
621   nop  ; or inc l
622   exx
623   ; load tile graphics
624   ld   sp,iy
625   pop  bc
626   pop  de
627   pop  af
628   exx
629   ld   sp,hl       ; put screen address to SP
630   exx
631 pusherAddress: equ $+1
632   jp   0           ; self-patching code; jump to 'pusher'
633 blitMapPusherDone: ; 'pushers' will return here
634   ld   de,6        ; tiles gfx are 6x16
635   add  iy,de
636   add  ix,de
637   exx
638   djnz blitMapNextLine
639   ; move to next map row
640   ; DE: table with 'pusher' addresses and tile offsets
641   ; get next 'pusher' address
642   ld   a,(de)
643   ld   (pusherAddress),a
644   inc  e
645   ld   a,(de)
646   ld   (pusherAddress+1),a
647   inc  e
648 blitMapGfxOfs: equ $+1
649   ld   bc,0               ; tile grafix offset
650   ; get tile gfx addresses
651   ld   a,(de)
652   ld   yl,a
653   inc  e
654   ld   a,(de)
655   ld   yh,a
656   inc  e
657   add  iy,bc
658   ld   a,(de)
659   ld   xl,a
660   inc  e
661   ld   a,(de)
662   ld   xh,a
663   inc  e
664   add  ix,bc
665   ld   b,16  ; 16 lines of next tile row
666   jp   blitMapNextLine
667   ;
668 blitMapDone:
669   ld   sp,(savedSP)
670   ret
671   DISPHEX "blitMap: start=#", blitMap, "; end=#", $, "\n"
674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
675 ;; part of code to get new graphics
676 ;; intended for copying
677 codeReloadTileGfx:
678   ld   (relGfxSavedSP),sp  ; 4 bytes
679   ld   sp,ix          ; 2 bytes
680   pop  bc             ; 1 byte
681   pop  de             ; 1 byte
682   pop  af             ; 1 byte
683   ld   sp,(relGfxSavedSP)  ; 4 bytes
684   ; total: 13 bytes
685 codeReloadTileGfxLen: equ $-codeReloadTileGfx
688 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
689 ;; calculate address in the map
690 ;; IN:
691 ;;   H: y
692 ;;   L: x
693 ;; OUT:
694 ;;   HL: map address
695 ;;   AF: dead
696 calcMapAddr:
697   srl  l
698   ld   a,h
699   rrca
700   rrca
701   rrca
702   ld   h,a
703   and  0E0h
704   or   l
705   ld   l,a
706   ld   a,h
707   and  1Fh
708   add  a,80h
709   ld   h,a
710   ret
713 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
715 buildPushers:
716   ld   hl,(mapX)
717   call calcMapAddr
718   or   a
719   ; up one row due to 'next map row' below
720   ld   bc,32
721   sbc  hl,bc
722   ld   (bldCurMapAddr),hl
723   ;
724   ld   hl,pusherStart
725   ld   (.bldPusherStartAddrVar),hl
726   ;
727   ld   hl,pusherJumpTable
728   ld   b,9  ; 9 tile rows
729 .bldPusherNextRow:
730   push bc
731   ; store current 'pusher' address
732 .bldPusherStartAddrVar: equ $+1
733   ld   de,0
734   ld   (hl),e
735   inc  l
736   ld   (hl),d
737   inc  l
738   push hl
739   push de
740   exx
741 @bldCurMapAddr: equ $+1
742   ; next map row
743   ld   hl,0
744   ld   de,32
745   add  hl,de
746   ; wrap y
747   ld   a,h
748   and  7
749   add  a,80h
750   ld   h,a
751   ;
752   ld   (bldCurMapAddr),hl
753   ; pop 'pusher' address
754   pop  de
755   ld   a,0FFh
756   ld   (bldCurTileBlockX2Var),a
757   ld   b,8  ; 8 bytes/16 tiles
758   ;
759   ld   a,(mapX)
760   and  1
761   jp   z,.bldEvenX
762   ; odd x
763 .bldNextMapByte:
764   ld   a,(hl)  ; map data
765   or   a
766   jr   nz,.bldNonEmptyTile
767   ld   a,#E5   ; PUSH HL (2 empty tiles)
768   ld   (de),a
769   inc  e
770 .bldStorePushAndBackOneMapByte:
771   ld   (de),a
772   inc  de
773   ; back one map byte, with wrapping
774   ld   a,l
775   and  0E0h
776   ld   c,a
777   ld   a,l
778   dec  a
779   and  1Fh
780   add  a,c
781   ld   l,a
782   djnz .bldNextMapByte
783   jp   .bldPusherDone
784 ; ---------------------------------------------------------------------------
785 .bldEvenX:
786   ; put only one tile instead of two
787   ld   a,(hl)  ; map data
788   or   a
789   jr   nz,.bldNonEmptyTileEX
790   ld   a,#E5   ; PUSH HL (empty tile)
791   jp   .bldStorePushAndBackOneMapByte
792 .bldNonEmptyTileEX:
793   and  0F0h
794   srl  a
795   srl  a
796   srl  a
797   ld   (bldCurTileBlockX2Var),a
798   call bldStoreTileBlockOffset
799   ld   a,(hl)  ; map data
800   push hl
801   and  0Fh     ; block type
802   add  a,a
803   add  a,pushCodes%256
804   ld   l,a
805   ld   h,pushCodes/256
806   jp   .bldCopyOnePush
807 ; ---------------------------------------------------------------------------
808 .bldNonEmptyTile:
809   and  0F0h
810   srl  a
811   srl  a
812   srl  a
813   ld   (bldCurTileBlockX2Var),a
814   call bldStoreTileBlockOffset
815   ld   a,(hl)
816   push hl
817   jr   .bldWeAreNotEmptyAnyway
818 .bldDoNextTiles:
819   ld   a,(hl)
820   push hl
821   or   a
822   jr   z,.bldItIsEmpty
823   push af
824   and  0F0h
825   srl  a
826   srl  a
827   srl  a
828   ld   c,a  ; new tileset
829 bldCurTileBlockX2Var: equ $+1
830   ld   a,0
831   cp   c
832   jp   z,.bldSameTileBlock
833   ld   a,c
834   ld   (bldCurTileBlockX2Var),a
835   call bldStoreTileBlockOffset
836   ; copy 'gfx switch' code
837   ld   a,b
838   push hl
839   ld   hl,codeReloadTileGfx
840   DUP  codeReloadTileGfxLen
841   ldi
842   EDUP
843   pop  hl
844   ld   b,a
845 .bldSameTileBlock:
846   pop  af
847 .bldWeAreNotEmptyAnyway:
848   and  0Fh
849 .bldItIsEmpty:
850   add  a,a
851   add  a,pushCodes%256
852   ld   l,a
853   ld   a,pushCodes/256
854   adc  a,0
855   ld   h,a
856   ld   a,(hl)
857   ld   (de),a
858   inc  de
859 .bldCopyOnePush:
860   inc  l
861   ld   a,(hl)
862   ld   (de),a
863   inc  de
864   pop  hl
865   ; previous map byte, with wrapping
866   ld   a,l
867   and  0E0h
868   ld   c,a
869   ld   a,l
870   dec  a
871   and  1Fh
872   add  a,c
873   ld   l,a
874   djnz .bldDoNextTiles
875 .bldPusherDone:
876   dec  de          ; remove one push (border)
877   ld   a,(mapX)
878   and  1
879   jr   z,$+3       ; skip next command
880   dec  de          ; remove another push (map is shifted by one tile)
881   ex   de,hl       ; HL: 'pusher' end
882   ; insert final JP
883   ld   (hl),0C3h   ; JP
884   inc  hl
885   ld   (hl),blitMapPusherDone%256
886   inc  hl
887   ld   (hl),blitMapPusherDone/256
888   inc  hl
889   ld   (.bldPusherStartAddrVar),hl  ; save this address
890   pop  hl          ; 'pusher' table
891   ; next table item
892   ld   a,l
893   add  a,4
894   ld   l,a
895   pop  bc
896   dec  b
897   jp   nz,.bldPusherNextRow
898   ret
900 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
902 bldStoreTileBlockOffset:
903   ;  A: tile block, 0-3
904   exx
905   ; DE: 'pusher' address
906   ; HL: pusher table
907   ex   de,hl
908   ; get tile block offset
909   ld   l,tileBlockOffsets%256
910   add  a,l
911   ;
912   ld   l,a
913   ld   a,tileBlockOffsets/256
914   adc  a,0
915   ld   h,a
916   ;
917   ld   c,(hl)
918   inc  hl
919   ld   b,(hl)
920   ex   de,hl
921   ; HL: pusher table
922   ; store tile block offset
923   ld   (hl),c
924   inc  hl
925   ld   (hl),b
926   inc  hl
927   exx
928   ret
929   DISPHEX "buildPushers: start=#", buildPushers, "; end=#", $, "\n"
932 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
934 ;; throwaways
935   org  #F000
936 firstTimeInit:
937   di
938   ld   sp,myfirstbyte
939   ;; set paging
940   ld   bc,#7FFD
941   ld   a,020
942   out  (c),a
943   ;;
944   ;ld   a,intrTable/256
945   ld   a,#39
946   ld   i,a
947   ld   a,#18
948   ld   (#FFFF),a  ; jr
949   ld   a,#C3      ; jp
950   ld   (#FFF4),a
951   ld   hl,IntrHandler
952   ld   (#FFF5),hl
953   im   2
954   ei
955   xor  a
956   ld   hl,#5800
957   ld   de,#5801
958   ld   bc,767
959   halt
960   di
961   ld   (hl),a
962   out  (254),a
963   ldir
964   ;call BuildScrLineTable
966 BuildScrLineTable:
967   ld   hl,scrRowsTable
968   ld   de,#401E
969   ld   b,128
970 .lineloop:
971   ld   (hl),e
972   inc  l
973   ld   (hl),d
974   inc  l
975   ; line down
976   inc  d
977   ld   a,d
978   and  #07
979   jr   nz,.downdone
980   ld   a,e
981   sub  #E0
982   ld   e,a
983   sbc  a,a
984   and  #F8
985   add  a,d
986   ld   d,a
987 .downdone:
988   djnz .lineloop
989   ;ret
990   jp   mainEntry