-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAD - Source - 2003.asm
1714 lines (1396 loc) · 36.5 KB
/
MAD - Source - 2003.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; © Dharmesh Malam 2003
; Memory Addressed Display Software Stack
; This program is free software: you can redistribute
; it and/or modify it under the terms of the
; GNU General Public License as published by the
; Free Software Foundation, either version 3 of
; the License, or (at your option) any later version.
; This program is distributed in the hope that
; it will be useful, but WITHOUT ANY WARRANTY;
; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
; See the GNU General Public License for more details.
; A copy of the GNU General Public License is
; available here <http://www.gnu.org/licenses/>.
; routine table
outram equ 0400h
find_pixel equ 0441h
sdr8_cl equ 048ah
put_pixel equ 046ah
remove_pixel equ 0472h
change_pixel equ 047bh
test_pixel equ 0483h
clear_vram equ 051ch
put_char equ 0529h
put_small equ 0565h
rand equ 0634h
binbcd equ 0646h
put_num equ 069ch
wait equ 06b2h
pause equ 06bch
sound equ 0726h
sound_test equ 0759h
menu equ 0044h
logo equ 0120h
vidram equ 0800h
pause_temp equ 8080h
clipflag equ 0902h
sound_0 equ 0903h
sound_1 equ 0904h
sound_2 equ 0905h
puttext equ 0950h
randseed equ 0960h
bcd16 equ 0961h
bcd16string equ 0966h
;-------------------------------------------------------
;Routine to update external ram with internal VRAM buffer
;© Dharmesh Malam 2003
;pin 0 = trisate port 1 and 2, when high, ports are high impedance, i.e. active low
;pin 1 = main display clock enable, active high, high for normal operation
;pin 2 = reset column/row select logic, active high
;pin 3 = reset ram counter, active high
;pin 4 = /rd ,active low
;pin 5 = /wr ,active low
;pin 6 =manual clock of ram
;pin 7 =/en2, low for normal operation
;normal mode
;76543210
;00100011
;routine stops mdc
;then resets column,row logic, disables screen
;then reset ram counter
;makes /rd high
;load data on ports 1 and 2
;enables port tristates
;pulse /wr
;pulse clock
;repeat until all ram is updated
;disable port tristates
;reset logic, and ram counter
;make /rw low
;start mdc
;return
#include zinc.asm
org outram
outram:
di ; disables interrupts, for speed
ex af,af' ;'
exx
; 00100011
ld a,10110001b ; make /rd high, and stop mdc, /en2 -> high
out (2),a ; output
ld a,10111101b ; make reset on col/row logic and ram counter high
out (2),a ; output
ld a,10110100b ; keeps col/row logic high, and makes ram counter low, and enables tristates
out (2),a ; output
ld hl,vidram ; point to vidram
ld b,56 ; set counter 28*2=56
out_loop:
ld c,0 ; set port pointer to 0
ld d,(hl) ; get byte
out (c),d ; output to port 0
inc hl ; increment pointer
inc c ; increment port counter
ld d,(hl) ; get next byte
out (c),d ; output to port 1
; pulse /wr
ld a,10010100b ; make /wr low
out (2),a ; output
ld a,10110100b ; make /wr high
out (2),a ; output
; pulse clock to ram
ld a,11110100b ; make clock high
out (2),a ; output
ld a,10110100b ; make clock low
out (2),a ; output
inc hl ; increment pointer
djnz out_loop ; loop until entire ram is refreshed
ld a,10111101b ; reset ram counter, and disable tristates
out (2),a ; output
ld a,10100001b ; pull above resets low, and make /rd low
out (2),a ; output
ld a,00100011b ; enable mdc,and /en2
out (2),a ; output
ex af,af' ;'
exx
ei ; re-enable interrupts
ret
end
;-------------------------------------------------------
;© Dharmesh Malam 2003
; Boot code
org 000h
start:
ld sp,0fffh ; initialise stack
im 1
xor a
ld (0903h),a
ld (0904h),a
ld (0905h),a
inc a
ld (0960h),a
ei
call clear_vram
jp logo
;--------------------------------------------------------
;© Dharmesh Malam 2003
; Clear video ram
org clear_vram
clear_vram:
push hl
xor a ; zero a
ld hl,vidram
ld b,112 ; rows/8 * columns
clear:
ld (hl),a
inc hl
djnz clear ; clear vidram
pop hl
ret
;if sound_x is zero, turn off sound
;if sound_x is non-zero, then turn on sound for that many 100ths sec
sound_0 equ 0903h
sound_1 equ 0904h
sound_2 equ 0905h
snd:
push bc
ld b,0
snd_0:
ld a,(sound_0) ; get sound var
cp 0 ; is it zero
jr z,snd_1 ; if so end sound
dec a ; otherwise dec counter
ld (sound_0),a ; save back
set 0,b ; set 0
jr snd_1
snd_1:
ld a,(sound_1)
cp 0
jr z,stop_1
dec a
ld (sound_0),a
set 0,b
jr snd_2
snd_2:
ld a,(sound_2)
cp 0
jr z,out_snd
dec a
ld (sound_0),a
set 0,b
out_snd:
ld a,b
out (3),a
pop bc
ret
;--------------------------------------------------------------
;© Dharmesh Malam 2003
; returns pseudo random 8 bit number in a.
; (r_seed) is a in ram byte must be initialised to a non zero value
;or this function will always return zero
rand_8:
ld a,(r_seed) ; get seed
and 184 ; mask non feedback bits
scf ; set carry
jp po,no_clr ; skip clear if odd
ccf ; complement carry (clear it)
no_clr:
ld a,(r_seed) ; get seed back
rla ; rotate carry into byte
ld (r_seed),a ; save back for next prn
ret ; done
r_seed:
db,1 ; prng seed byte (must not be zero)
;---------------------------------------------------------------
;© Dharmesh Malam 2003
;find pixel routine for 3,4x6, (21,28x30 dots)
;b=x c=y
;origin is top left corner
vidram equ 0fc00h
org 0000h
find_pixel:
push bc ; save bc
ld hl,vidram ; start of video ram
ld a,c ; a=y times y by how many bytes per row
sla a ; a=2y
sla a ; a=4y
ld l,a ; l=4y
ld a,b ; a=x
srl a ; a=int(x/2)
srl a ; a=int(x/4)
srl a ; a=int(x/8)
add a,l ; a=int(x/8) + 4y
ld l,a ; l=int(x/8) + 4y, so hl point to right byte
ld a,b ; a=x
and 7 ; mask a,0000111,so which bit selected
ld bc,fp_bits ; bc point to first bit mask
add a,c ; simulated 16 bit addition,
ld c,a ; ..need even though 7 is max
adc a,b ; ..as fp-bits is a 16 bit address
sub c ; ..
ld b,a ; .., bc points to right mask
ld a,(bc) ; a=mask
pop bc ; restore bc
ret ; return to caller
fp_bits: db 80h,40h,20h,10h,08h,04h,02h,01h
;----------------------------------------------------------
;basic pixel operations
;© Dharmesh Malam 2003
;all destroy a and need findpixel
#include zinc.asm
put_pixel: ; blit pixel at b,c
push hl
call findpixel
or (hl)
ld (hl),a
pop hl
ret
remove_pixel: ; remove pixel at b,c
push hl
call findpixel
cpl
and (hl)
ld (hl),a
pop hl
ret
change_pixel: ; change pixel at b,c
push hl
call findpixel
xor (hl)
ld (hl),a
pop hl
ret
test_pixel: ; tests pixel at b,c
push hl
call findpixel
and (hl) ; zero flag set if no pixel
pop hl
ret
;----------------------------------------------------------
;sprite drawing routine (sdr): 8 bit clipping version
;© Dharmesh Malam 2003
;inputs:
; b=x coordinate
; c=y coordinate
; hl=pointer to sprite data
;outputs:
; af=destroyed
; bc=restored
; de=restored
; hl=restored
; no other registers are changed
;;sprite data should be stored as follows:
;db (# rows/bytes/height of sprite)
;db (bitmap of sprite)
;;notes:
;; if x between -1 and -7, then some left clipping,
;......less than or equal to -8, then return
;if x bewtween 0 and 22, then no clipping
;if x between 23 and 29, then right clipping
;if x greater than 30, then return
;if y less than or equal to -(lenght), then return t
;if y between -1 and -(lenght)+1, then top clippng t
;if y bewtwenm 0 and (27-lenght), then no clipping n
;if y between (27-lenght)+1 and 27, then bottom clipping b
;if y greater than 28, then return b
org sdr8_cl
clipflag: db,0
sdr8_cl:
push bc ; save registers
push de
push hl
ld e,(hl) ; e=number of rows in sprite
inc hl ; next byte (points to sprite now)
xor a ; zero a
ld (clipflag),a ; clear clipflag
; top clipping done
check_right:
ld a,b ; a=x coor
bit 7,b ; is x negative?
jr nz,sdr8cl_checklclip ; if so then jump to check left
cp 30 ; check if x is greater than or equal to 30
jr nc,endsdr ; if so, then carry is set, and jump
jr check_bot ; else, done l/r clipping (right clipping is "automatic")
sdr8cl_checklclip: ; now check left clipping
cp -7 ; check if starts too far left
jr c,endsdr ; if so, sprite won't show
add a,32 ; add 32 to x coor to make it start on right side and wrap
ld b,a ; save into x coor
ld (clipflag),a ; and make flag non-zero
check_bot: ; check for bottom clipping
bit 7,c
jr nz,check_top ; is y negative, then jump to check top
ld a,c ; get y-coord
cp 28 ; check if greater than 28
jr nc,endsdr ; y is greater than 28, so end, as not viewable
ld a,28 ; number of rows in display
sub e ; subtract rows in sprite
cp c ; compare to y-coord
jr nc,sdr8cl_doneclip ; if no carry, then no bottom clipping
; so clip bottom
ld a,28 ; rows in display
sub c ; subtract the y-coord
ld e,a ; use above result as reduced row counter
; bottom clipping done
jr sdr8cl_doneclip
check_top:
; y is neg
ld a,c ; a is -1 or less
add a,e ; subtract the number of rows in sprite
jr nc,endsdr ; if no-carry, then not on screen
; y is between -1 and -(lenght)+1
push bc ; save x,y coords
ld c,a ; c has number of rows to put
sub e ; make number inverse
neg
ld b,a ; b has counter to shift hl by
ld e,c ; c has e
sprite_shift: ; shift hl b times to clip it
inc hl
djnz sprite_shift
pop bc ; restore x,coords
ld c,0 ; y will always be o
sdr8cl_doneclip:
push hl ; push pointer to sprite to stack
call find_pixel
ld c,e ; c=number of rows in sprite
add a,a ; -> sets all bits to the right of the set bit (sprite mask)
dec a ; /
ld e,a ; save sprite mask into e
ld a,b ; get x coor
and 00000111b ; find remainder of x/8
inc a ; increase to get range of 1-8
ld b,a ; b=rotate counter
sdr8cl_newrow:
ex (sp),hl ; hl(video location)<->(sp)(pointer to sprite)
ld a,(hl) ; a=byte in sprite
inc hl ; next byte
ex (sp),hl ; hl<->(sp)
push bc ; save rotate counter and row counter
rlca ; rotate left once...
sdr8cl_prepbyte:
rrca ; ...then rotate right...
djnz sdr8cl_prepbyte ; ...b times
ld b,a ; save rotated sprite byte into b
ld a,(clipflag) ; a=left clipping flag
or a ; check if not 0
jr nz,sdr8cl_skipleft ; if left clipping, only display right half of sprite
ld a,b ; else, load rotated sprite byte back into a
and e ; mask off left bits
ld d,a ; (check sdr8 to see how this works...)
ld a,e
cpl
and (hl)
or d
ld (hl),a
inc hl
ld a,l ; a=lower byte of video location to put sprite
and 00000011b ; mask off upper nibble
jr z,sdr8cl_nextrow ; if zero, hl now points to a new row, so right clipping
jr sdr8cl_putright ; jump for normal drawing
sdr8cl_skipleft:
dec hl ; decrease hl by 3 to point it to start of row for clipping
dec hl
dec hl
sdr8cl_putright:
ld a,e ; a=sprite mask
cpl ; switch every byte
and b ; mask off right bits
ld d,a ; save masked sprite byte into d
ld a,e ; a=sprite mask (again)
and (hl) ; mask off bits where sprite's going to be put
or d ; set bits in sprite byte
ld (hl),a ; and put right half of sprite
sdr8cl_nextrow:
ld bc,4h-1 ; bc=number of bytes in one row-1
ld a,(clipflag) ; see if clipflag is zero
or a
jr z,left_skip ; if not, then add 7, as clipping changes values
ld bc,7
left_skip:
add hl,bc ; add to point hl to next row
pop bc ; restore rotate counter and row counter
dec c ; decrease row counter
jr nz,sdr8cl_newrow ; and repeat
pop hl ; restore pointer to sprite (now points to byte after sprite)
endsdr:
pop hl ; restore registers
pop de
pop bc
ret ; return
;------------------------------------------------------------------------------
; bintobcd
;; these routines format a registers into their ascii string equivalents, ie:
; the number 143 would be turned into
; .db "143", 0
;; bintobcd16 does not format strings with leading zeroes, ie:
; the number 353 would be turned into
; .db "353",0
; not
; .db "00353",0
; bintobcd16
; by joe pemberton
;size: 97 bytes
;;input:
;de=number to convert
;;returns (bcd16) as ten thousands, thousands, hundreds, tens, ones
;(bcd16string) contains the formatted bcd ascii string
;b = 0
;de = 0
;destroys af, bc, de, hl, ix
bintobcd16:
push de
ld hl,bcd16
ld de,bcd16+1
ld bc,10
ld (hl),0
ldir
pop de
ld b,16
bcd16l: ld hl,bcd16
push bc
ld b,5
bcd16i: ld a,(hl)
cp 5
jr c,bcd16a
add a,3
ld (hl),a
bcd16a: inc hl
djnz bcd16i
dec hl ;hl now points to the ones
ld b,5
sla e
rl d
bcd16b: rl (hl)
bit 4,(hl)
jr z,bcd16c
res 4,(hl)
scf
bcd16c: dec hl
djnz bcd16b
pop bc
djnz bcd16l
inc hl
ld ix,bcd16string
ld bc,(5*256)+0
bcd16d: ld a,(hl)
add a,30h
ld (ix+0),a
cp 30h
jr nz,bcd16e
bit 1,c
jr z,bcd16f
bcd16e: inc ix
set 1,c
bcd16f: inc hl
djnz bcd16d
ret
bcd16: db 0,0,0,0,0
bcd16string:
db 0,0,0,0,0,0
;------------------------------------------------------------------------
;© Dharmesh Malam 2003
;put 16 bit number de, at bc with smallfont
put_num
push de ; save
push hl
push ix
push bc
push bc
call bintobcd16
pop bc ; restore x,y
ld hl,bcd16string ; point to string
call putsmall ; draw
pop bc ; restore
pop ix
pop hl
pop de
ret
;-------------------------------------------------------------
;© Dharmesh Malam 2003
; library of character/text routines
; values and conversion of bases and ascii characters
;;1 = value in decimal
;2 = value in hexadecimal
;3 = value in binary
;4 = value in two's complement
;5 = ascii character if valid
; 1 2 3 4 5
; 32 20 00100000 32 space
; 33 21 00100001 33 !
; 34 22 00100010 34 "
; 35 23 00100011 35 #
; 36 24 00100100 36 $
; 37 25 00100101 37 %
; 38 26 00100110 38 &
; 39 27 00100111 39 '
; 40 28 00101000 40 (
; 41 29 00101001 41 )
; 42 2a 00101010 42 *
; 43 2b 00101011 43 +
; 44 2c 00101100 44 ,
; 45 2d 00101101 45 -
; 46 2e 00101110 46 .
; 47 2f 00101111 47 /
; 48 30 00110000 48 0
; 49 31 00110001 49 1
; 50 32 00110010 50 2
; 51 33 00110011 51 3
; 52 34 00110100 52 4
; 53 35 00110101 53 5
; 54 36 00110110 54 6
; 55 37 00110111 55 7
; 56 38 00111000 56 8
; 57 39 00111001 57 9
; 58 3a 00111010 58 :
; 59 3b 00111011 59 ;
; 60 3c 00111100 60 <
; 61 3d 00111101 61 =
; 62 3e 00111110 62 >
; 63 3f 00111111 63 ?
; 64 40 01000000 64 @
; 65 41 01000001 65 a
; 66 42 01000010 66 b
; 67 43 01000011 67 c
; 68 44 01000100 68 d
; 69 45 01000101 69 e
; 70 46 01000110 70 f
; 71 47 01000111 71 g
; 72 48 01001000 72 h
; 73 49 01001001 73 i
; 74 4a 01001010 74 j
; 75 4b 01001011 75 k
; 76 4c 01001100 76 l
; 77 4d 01001101 77 m
; 78 4e 01001110 78 n
; 79 4f 01001111 79 o
; 80 50 01010000 80 p
; 81 51 01010001 81 q
; 82 52 01010010 82 r
; 83 53 01010011 83 s
; 84 54 01010100 84 t
; 85 55 01010101 85 u
; 86 56 01010110 86 v
; 87 57 01010111 87 w
; 88 58 01011000 88 x
; 89 59 01011001 89 y
; 90 5a 01011010 90 z
; 91 5b 01011011 91 [
; 92 5c 01011100 92 \
; 93 5d 01011101 93 ]
; 94 5e 01011110 94 ^
; 95 5f 01011111 95 _
; 96 60 01100000 96 `
; 97 61 01100001 97 a
; 98 62 01100010 98 b
; 99 63 01100011 99 c
; 100 64 01100100 100 d
; 101 65 01100101 101 e
; 102 66 01100110 102 f
; 103 67 01100111 103 g
; 104 68 01101000 104 h
; 105 69 01101001 105 i
; 106 6a 01101010 106 j
; 107 6b 01101011 107 k
; 108 6c 01101100 108 l
; 109 6d 01101101 109 m
; 110 6e 01101110 110 n
; 111 6f 01101111 111 o
; 112 70 01110000 112 p
; 113 71 01110001 113 q
; 114 72 01110010 114 r
; 115 73 01110011 115 s
; 116 74 01110100 116 t
; 117 75 01110101 117 u
; 118 76 01110110 118 v
; 119 77 01110111 119 w
; 120 78 01111000 120 x
; 121 79 01111001 121 y
; 122 7a 01111010 122 z
; 123 7b 01111011 123 {
; 124 7c 01111100 124 |
; 125 7d 01111101 125 }
; 126 7e 01111110 126 ~
; 127 7f 01111111 127 delete
;put_string/char takes the ascii value, subtracts 32,
;so the first character is 'space', times by 8 and adds it to the font?_rom address.
;this will find the right character.
;bc points to x,y point to put string/char
;e has which font 1,2,3,4, being namco,coleco,speccy,and bbc
;hl, points to the string in put_string
;d, contains the character to display in put_char
org put_char
put_char: ; put the character in d, with small font, at bc
push hl ; save registers
push de
push bc
ld hl,small
char_start:
ld a,d ; load a with ascii code of character
sub 32 ; subtract 32, so first letter is 00, as per in rom
ld e,a ; put e with ascii code - 32
ld d,0 ; load d with 0, so de is the character needed
add hl,de
add hl,de
add hl,de ; so hl = offset + 3(ascii - 32)
; need to create 8*6 sprite from condensed data
ld a,6d ; length of sprite
ld (0950h),a ; load to ram
ld ix,0951h
ld b,3
sprite_out:
ld d,(hl) ; get first byte
ld a,0f0h ; split in two
and d ; by masking
ld (ix),a ; save to ram
inc ix ; next location in ram
ld a,0fh ; next mask
and d ; gets second half
rlca ; rotate left
rlca ; 4 times
rlca
rlca
ld (ix),a ; save next half
inc ix
inc hl
djnz sprite_out
ld hl,0950h ; pointer to sprte in ram
pop bc ; restore x,y coords
call sdr8_cl ; draw the character
pop de ; restore registers
pop hl
ret
put_small: ; put at bc, (x,y), string pointed to by hl, with small font,end at 0
; before: hl points to string, bc = xy
; after: hl points to end of string, , bc = (x+4chars),y,
; a=0, d=last byte
ld a,(hl) ; fetch byte
cp 0 ; is it zero
ret z ; if so, then return to caller
ld d,a ; put character into d for put_char
call put_char
ld a,b ; get x-coord
add a,4 ; shift x-coord by 5, as small font
ld b,a ; save
inc hl ; next byte
jr put_small ; jump to top,hence repeat until all char's are done
;-----------------------------------------------------------------------------
;© Dharmesh Malam 2003
org pause
pause:
in a,(0) ; get keys of pad 1
bit 0,a ; see if start was pressed
ret z ; return if it wasn't
ld c,2
call wait
in a,(0)
ret z
push hl ; save registers
push de
push bc
ld hl,vidram ; save screen, hl points to current screen
ld de,pause_temp ; temp screen
ld bc,112 ; size of screen
ldir ; save data
call clear_vram ; clear screen
ld hl,pause_text ; "pause"
ld b,6 ; off centre
ld c,8
call put_small ; put text
ld de,0 ; zero counter
text:
ld b,6 ; coors
ld c,16
call put_num
call outram
ld b,100
key_loop:
in a,(0)
bit 0,a
jr nz,unpause
ld c,2
call wait ; wait for a few ms
djnz key_loop ; check pad 100 time, then inc counter
inc de
jr text
unpause:
ld c,2
call wait
in a,(0)
bit 0,a
jr z,key_loop
ld hl,pause_temp ; opposite to above
ld de,vidram ; restore data
ld bc,112
ldir
call outram
pop bc ; restore registers
pop de
pop hl
ret ; then return
pause_text:
db "pause",0
;---------------------------------------------
;© Dharmesh Malam 2003
wait: ; call with c as multiplier
push bc ; save
wai2:
ld b,255
wai: ; inner loop
djnz wai
dec c
jr nz,wai2 ; outer loop
pop bc
ret
;© Dharmesh Malam 2003
;each font is 4x6, stored condensed
;------------------------------------
org font1_rom
; character 0x20 (space)
db 00000000b
db 00000000b
db 00000000b
; character 0x21 !
db 01000100b
db 01000000b
db 01000000b
; character 0x22 "
db 10101010b
db 10000000b
db 00000000b
; character 0x23 #
db 10101110b
db 10101110b
db 10100000b
; character 0x24 $
db 01001110b
db 01001110b
db 01000000b
; character 0x25 %
db 10100010b
db 01001000b
db 00100000b
; character 0x26 &
db 00001000b
db 10000000b
db 10100000b
; character 0x27 '
db 10001000b
db 00000000b
db 00000000b
; character 0x28 (
db 01001000b
db 10001000b
db 01000000b
; character 0x29 )
db 01000010b
db 00100010b
db 01000000b
; character 0x2a *
db 10100100b
db 11100100b
db 10100000b
; character 0x2b +
db 00000100b
db 11100100b
db 00000000b
; character 0x2c ,
db 00000000b
db 00000100b
db 10000000b
; character 0x2d -
db 00000000b
db 11100000b
db 00000000b
; character 0x2e .
db 00000000b
db 00000000b
db 10000000b
; character 0x2f /
db 00100100b
db 01001000b
db 00000000b
; character 0x30 0
db 01001010b
db 11101010b
db 01000000b
; character 0x31 1
db 01001100b
db 01000100b
db 11100000b
; character 0x32 2
db 01001010b
db 00100100b
db 11100000b
; character 0x33 3
db 11100010b
db 01000010b
db 11000000b
; character 0x34 4
db 10101010b
db 11100010b
db 00100000b
; character 0x35 5
db 11101000b
db 11000010b
db 11000000b