-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogic.asm
1201 lines (972 loc) · 26.3 KB
/
logic.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
; ***************************************************************************************
; ***************************************************************************************
; ** Bespoke function for game logic
; ** Require grafx.asm & roomdata.asm & roominfo.asm & miscdata.asm
.DATA
CHARSTYLE db 10h
; For saving purposes - keep CHAR_POS_X / CHAR_POS_Y together in that order!
CHAR_POS_X dw 160
CHAR_POS_Y dw 64
CHARACTER_MOVE dw 0007h
; set to next room if a door was hit
NEXT_ROOM db 0
ADJUST_POS_X dw 0
ADJUST_POS_Y dw 0
; If 1 - the newly added password in ADD_NEW_PASSWORD are displayed immmediately
DISPLAY_PASSWORD db 1
; if there was a change in room (i.e. room was just resolved), we want to redraw everything
; in this case set this to 1 - otherwise only a partial redrawing will be enough
CHANGE_IN_ROOM db 0
; previous position (prior move - to use to clean up sprite)
PREVIOUS_POS_X dw 0
PREVIOUS_POS_Y dw 0
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Current room details
ROOM_NUMBER db 0
ORIGINALROOM db 200 dup (0)
CURRENTROOM db 200 dup (0)
TARGETROOM db 200 dup (0)
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; All room specific info
; all the data below must remain in that order!
; flags for the room
; - bit 0 is set if room is changeable
; - bit 1 is set if room is completed
; - bit 2 is set if room generates a password upon solving
ROOM_FLAGS db 001b
PASSCODE_ROOM db 0 ; reference to passcode
; Assume one action per door and up to 4 doors per room
; First byte is destination room - higher bit is set to 1 if door is open
; Next byte is reference to password (need to store password somewhere - there can be 27 in total for 3 players)
ACTION_LIST db 2, 0
db 6 dup (0)
ROOM_CLUE db 85 dup (0)
; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Pre-mapped data
; contains all the position to be called
JUMP_POS dw 256 dup (0)
; ************************************************************************************
; ** A few macros
GET_NEXT_ROOM MACRO
; get the corresponding action
xor ah, ah
mov al, [si + offset TARGETROOM]
dec al
shl al, 1
mov di, offset ACTION_LIST
add di, ax
mov al, [di]
; remove the open door flag
and al, 7fh
mov [NEXT_ROOM], al
ENDM
GET_PASSWORD_REFERENCE MACRO
; get the corresponding action
xor ah, ah
mov al, [si + offset TARGETROOM]
dec al
shl al, 1
mov di, offset ACTION_LIST
add di, ax
inc di
mov al, [di]
ENDM
.CODE
GENERATE_JUMP_POSITION:
push ds
pop es
; All keys defaults to DO_NOTHING
mov di, offset JUMP_POS
mov ax, offset DO_NOTHING
mov cx, 256
rep stosw
; now add specific moves
mov di, offset JUMP_POS
mov ax, offset MOVE_CHARACTER_LEFT
mov [di + 4bh * 2], ax
mov ax, offset MOVE_CHARACTER_RIGHT
mov [di + 4dh * 2], ax
mov ax, offset MOVE_CHARACTER_UP
mov [di + 48h * 2], ax
mov ax, offset MOVE_CHARACTER_DOWN
mov [di + 50h * 2], ax
mov ax, offset PRESS_SPACE
mov [di + 39h * 2], ax
ret
RESET_CHARACTER_STANCE:
; Reset the character pose if no keys are being pressed
; BL is modified
; problem here is that - we read the keyboard too often and it resets to zero too quickly
mov ax, CHARACTER_STEP
mov [CHARACTER_MOVE], ax
mov al, [CHARACTERSPRITE]
and al, 0F0h
mov [CHARACTERSPRITE], al
ret
MOVE_CHARACTER_LEFT:
; Move character left
; read the sprite - make sure it points to the right direction
; and add some movement
mov al, [CHARACTERSPRITE]
and al, 0Fh
inc al
and al, 11b
mov ah, 30h
add al, ah
mov [CHARACTERSPRITE], al
; Now move the position
mov ax, [CHAR_POS_X]
sub ax, [CHARACTER_MOVE]
mov [CHAR_POS_X], ax
; Collision detection - did we hit a wall ?
; Find corresponding tile of middle left side --> we need to have (CHAR_POS_Y + 8) / 16 * 20 + CHAR_POS_X / 16
push bx
push dx
mov si, [CHAR_POS_Y]
add si, 8
;;; keep an eye on the edge case (if middle of sprite is past the bottom of tile, we check the tile above, otherwise we check the tile below)
;;; if 4th bit in SI is set, we will shift SI by -1 later, otherwise we shift by 1
;;mov dx, si
;;and dx, 1000b
;;shr dx, 2
;;dec dx
;;neg dx
;;shl dx, 4
;shr si, 4
;mov bx, si
;shl si, 4
;shl bx, 2
and si, 0fff0h
mov bx, si
shr bx, 2
add si, bx
add ax, CHARACTER_BUFFER_LEFT
shr ax, 4
add si, ax
;;; check next tile
;;add si, dx
;;mov bl, [si + offset CURRENTROOM]
;;mov bh, bl
; check middle tile
;;sub si, dx
mov bl, [si + offset CURRENTROOM]
;;xchg bh, bl
;;or bl, bh
mov bh, bl
and bl, 0fh
and bl, 11111100b
jz @@all_good
shl ax, 4
add ax, 16 - CHARACTER_BUFFER_LEFT
mov [CHAR_POS_X], ax
; Password management here
cmp bh, CLOSED_LEFT_DOOR
jnz @@not_a_closed_door
call CHECK_CALL_FOR_PASSWORD
@@not_a_closed_door:
; is it an open door ?
cmp bh, LEFT_DOOR
jnz @@all_good
add ax, 16 * 17
mov [ADJUST_POS_X], ax
mov ax, [CHAR_POS_Y]
mov [ADJUST_POS_Y], ax
GET_NEXT_ROOM
@@all_good:
pop dx
pop bx
pop si
pop ax
ret
MOVE_CHARACTER_RIGHT:
; Move character right
; read the sprite - make sure it points to the right direction
; and add some movement
mov al, [CHARACTERSPRITE]
and al, 0Fh
inc al
and al, 11b
mov ah, 40h
add al, ah
mov [CHARACTERSPRITE], al
; Now move the position
mov ax, [CHAR_POS_X]
add ax, [CHARACTER_MOVE]
mov [CHAR_POS_X], ax
; Collision detection - did we hit a wall ?
; Find corresponding tile of middle right side --> we need to have (CHAR_POS_Y + 8) / 16 * 20 + (CHAR_POS_X + 16) / 16
push bx
mov si, [CHAR_POS_Y]
add si, 8
shr si, 4
mov bx, si
shl si, 4
shl bx, 2
add si, bx
add ax, 16 - CHARACTER_BUFFER_RIGHT
shr ax, 4
add si, ax
mov bl, [si + offset CURRENTROOM]
mov bh, bl
and bl, 0fh
and bl, 11111100b
jz @@all_good
shl ax, 4
sub ax, 16 - CHARACTER_BUFFER_RIGHT
mov [CHAR_POS_X], ax
; Password management here
cmp bh, CLOSED_RIGHT_DOOR
jnz @@not_a_closed_door
call CHECK_CALL_FOR_PASSWORD
@@not_a_closed_door:
; is it an open door ?
cmp bh, RIGHT_DOOR
jnz @@all_good
sub ax, 16 * 17
mov [ADJUST_POS_X], ax
mov ax, [CHAR_POS_Y]
mov [ADJUST_POS_Y], ax
GET_NEXT_ROOM
@@all_good:
pop bx
pop si
pop ax
ret
MOVE_CHARACTER_UP:
; Move character up
; read the sprite - make sure it points to the right direction
; and add some movement
mov al, [CHARACTERSPRITE]
and al, 0Fh
inc al
and al, 11b
mov ah, 20h
add al, ah
mov [CHARACTERSPRITE], al
; Now move the position
mov ax, [CHAR_POS_Y]
sub ax, [CHARACTER_MOVE]
mov [CHAR_POS_Y], ax
; Collision detection - did we hit a wall ?
; Find corresponding tile of upper middle side --> we need to have CHAR_POS_Y / 16 * 20 + (CHAR_POS_X + 8) / 16
push bx
mov si, ax
sub si, CHARACTER_BUFFER_UP
shr si, 4
mov bx, si
shl si, 4
shl bx, 2
add si, bx
mov bx, [CHAR_POS_X]
add bx, 8
shr bx, 4
add si, bx
mov bl, [si + offset CURRENTROOM]
mov bh, bl
and bl, 0fh
and bl, 11111100b
jz @@all_good
and ax, 0FFF0h
add ax, 16 - CHARACTER_BUFFER_UP
mov [CHAR_POS_Y], ax
; Password management here
cmp bh, CLOSED_UP_DOOR
jnz @@not_a_closed_door
call CHECK_CALL_FOR_PASSWORD
@@not_a_closed_door:
; is it an open door ?
cmp bh, UP_DOOR
jnz @@all_good
add ax, 16 * 7
mov [ADJUST_POS_Y], ax
mov ax, [CHAR_POS_X]
mov [ADJUST_POS_X], ax
GET_NEXT_ROOM
@@all_good:
pop bx
pop si
pop ax
ret
MOVE_CHARACTER_DOWN:
; Move character down
; read the sprite - make sure it points to the right direction
; and add some movement
mov al, [CHARACTERSPRITE]
and al, 0Fh
inc al
and al, 11b
mov ah, 10h
add al, ah
mov [CHARACTERSPRITE], al
; Now move the position
mov ax, [CHAR_POS_Y]
add ax, [CHARACTER_MOVE]
mov [CHAR_POS_Y], ax
; Collision detection - did we hit a wall ?
; Find corresponding tile of lower middle side --> we need to have (CHAR_POS_Y + 16) / 16 * 20 + (CHAR_POS_X + 8) / 16
push bx
mov si, ax
add si, 16 + CHARACTER_BUFFER_DOWN
shr si, 4
mov bx, si
shl si, 4
shl bx, 2
add si, bx
mov bx, [CHAR_POS_X]
add bx, 8
shr bx, 4
add si, bx
mov bl, [si + offset CURRENTROOM]
mov bh, bl
and bl, 0fh
and bl, 11111100b
jz @@all_good
add ax, 16
and ax, 0FFF0h
sub ax, 16 - CHARACTER_BUFFER_DOWN
mov [CHAR_POS_Y], ax
; Password management here
cmp bh, CLOSED_DOWN_DOOR
jnz @@not_a_closed_door
call CHECK_CALL_FOR_PASSWORD
@@not_a_closed_door:
; is it an open door ?
cmp bh, DOWN_DOOR
jnz @@all_good
sub ax, 16 * 7
mov [ADJUST_POS_Y], ax
mov ax, [CHAR_POS_X]
mov [ADJUST_POS_X], ax
GET_NEXT_ROOM
@@all_good:
pop bx
pop si
pop ax
ret
PRESS_SPACE:
; check the room can still change
mov al, [ROOM_FLAGS]
and al, 1b
jz @@done_press_space
; get position - roughly around where the waist is
mov si, [CHAR_POS_Y]
add si, 11 ; move to waist
shr si, 4
mov ax, si
shl si, 4
shl ax, 2
add si, ax
mov ax, [CHAR_POS_X]
add ax, 8
shr ax, 4
add si, ax
; now get tile - little trick, only tile 2 and 3 can be swapped
; tile 0 and 1 can't (to be used to fix certain tiles)
mov al, [si + offset CURRENTROOM]
mov ah, al
and ah, 10b
shr ah, 1
xor al, ah
mov [si + offset CURRENTROOM], al
; we need know to confirm if the room matches the target
call VALIDATE_ROOM
call STORE_ROOM_VIDEO_RAM
@@done_press_space:
pop si
pop ax
ret
DO_NOTHING:
pop si
pop ax
ret
UPDATE_CHARACTER_STANCE_DIRECTION:
push ax
push si
xor ah, ah
mov si, offset JUMP_POS
shl ax, 1
add si, ax
mov ax, [si]
jmp ax
; That bit should not be used since the functions have a ret, but just in case
pop si
pop ax
ret
STORE_ROOM_VIDEO_RAM:
pusha
mov ax, [VIDEO_BUFFER]
mov es, ax
; move the tile config to the end of buffer
; this is to avoid using 3 segment (video buffer + screen tiles config + tiles gfx)
; tile config is 20 * 10 bytes = 200 bytes (there is 65535 - 64000 = 1535 bytes left)
mov si, offset CURRENTROOM
mov di, 320 * 200
mov cx, 100
rep movsw
; then we can add the corresponding position in the image for each tile
; this takes an additional 400 bytes (since address is a word)
push ds
mov ds, ax
mov si, 320*200
mov di, 320*200+200
mov cx, 200
@@loop_tileaddresses:
; to convert the tile number into a position - easy now if we use x256
mov al, es:[si]
xor ah, ah
shl ax, 4
shl ah, 4
stosw
inc si
dec cx
jnz @@loop_tileaddresses
pop ds
popa
ret
VALIDATE_ROOM:
; Check whether the current room matches the target room
; ignore the boundaries - we assume all doors are on boundaries (whether they are open is not a target)
; so we start on the second tile of the first row
; AX and SI will be changed (should be ok because it's only called from PRESS_SPACE which saved them in the stack)
push es
push cx
push di
mov si, offset CURRENTROOM
add si, 21
mov di, offset TARGETROOM
add di, 21
push ds
pop es
; checking each row and adding the remainder of cx (should be zero after each line)
; there are 9 words in each row if we ignore the boundaries
mov al, 8
@@check_row:
mov cx, 19
repe cmpsb
; if cx is not zero, a difference was found somewhere
or cx, cx
jnz @@end_check
; if zero, let's move to the next row
; si and di should be on the boundary of the previous row
add si, 1
add di, 1
dec al
jnz @@check_row
; if all identical - flag the room as done
mov al, [ROOM_FLAGS]
or al, 10b
and al, 11111110b
mov [ROOM_FLAGS], al
; confirm that there is a change that requires to redraw everything
mov byte ptr [CHANGE_IN_ROOM], 1
; Now that we know the room is solved, we need to check each door
; we check each side independently (we can ignore each corner)
; top side
mov si, offset TARGETROOM + 1
mov cl, 18
mov ch, 1
call CHECK_SIDE
; left side
mov si, offset TARGETROOM + 20
mov cl, 9
mov ch, 20
call CHECK_SIDE
; right side
mov si, offset TARGETROOM + 19
mov cl, 9
mov ch, 20
call CHECK_SIDE
; bottom side
mov si, offset TARGETROOM + 20*9
mov cl, 18
mov ch, 1
call CHECK_SIDE
; Now check if there is a new password attributed after solving
mov si, offset PASSCODE_ROOM
mov al, [si]
or al, al
jz @@end_check
call ADD_NEW_PASSWORD
@@end_check:
pop di
pop cx
pop es
ret
ADD_NEW_PASSWORD:
; subroutine to add a new password if needed
; AL contains the reference to the password
pusha
; 8 bytes per password - SI points to the password
dec al
shl al, 3
inc al
xor ah, ah
mov si, offset ALL_PASSCODE
add si, ax
; make sure we write it at the right place
; AX will contain the row/columns (AH row and AL column)
; and DI will point to the right position
mov di, 14 + offset PASSCODEAREA
mov ax, [si + 4]
; we need to multiply AL by 4 (easy)
; and AH by 13 (harder) --> x13 = x8 + x4 + x1
xor cx, cx
dec al
shl al, 2
mov cl, al
dec ah
mov al, ah
shl ah, 2 ; x4
add al, ah ; adding on top of x1
shl ah, 1 ; x8 now
add al, ah
add cl, al
add di, cx
; now update the password area
push ds
pop es
mov cl, 3
@@update_password_area:
xor ah, ah
lodsb
mov bx, offset LETTER_MAPPING
sub ax, 20h
add bx, ax
mov al, [bx]
stosb
dec cl
jnz @@update_password_area
; do we need to display it ?
mov al, [DISPLAY_PASSWORD]
or al, al
jz @@no_pass_display
mov ax, [SCREEN_PTR+2]
call GENERATE_PASSWORDAREA
@@no_pass_display:
popa
ret
CHECK_SIDE:
; subroutine to check doors on side
; SI points to the top-left corner of the side of interest
; CL is the number of iteration
; CH is the SI increment
xor ah, ah
@@iter_side:
mov al, [si]
or al, al
jz @@notadoor
; if it's a door, check the corresponding action
dec al
shl al, 1
mov di, offset ACTION_LIST
add di, ax
inc di
; can we open it ?
mov al, [di]
or al, al
jnz @@notadoor
dec di
;; now flag as open - deprecated (not sure this flag serves any purpose)
;mov al, [di]
;or al, 10000000b
;mov [di], al
; and change the tile - the target room and current room are 200 bytes away
sub si, 200
mov al, [si]
or al, 10h
mov [si], al
add si, 200
@@notadoor:
mov al, ch
add si, ax
dec cl
jnz @@iter_side
ret
GENERATE_CLUEAREA:
; Generate the clue area (bottom right)
; AX contains the tileset reference
; CL contains length of area (in multiples of 8)
push si
push dx
push cx
mov si, offset CLUEAREA
mov dx, 104
mov cl, 27
call GENERATE_AREA
pop cx
pop dx
pop si
ret
GENERATE_PASSWORDAREA:
; Generate the password area (bottom left)
; AX contains the tileset reference
push si
push dx
push cx
mov si, offset PASSCODEAREA
mov dx, 0
mov cl, 13
call GENERATE_AREA
pop cx
pop dx
pop si
ret
GENERATE_AREA:
; Generate one of the areas, either password or clue (bottom left or right)
; SI must point to the tile reference in DS
; AX contains the tileset reference
; DX contains the horizontal shift reference
; CL contains length of area (in multiples of 8)
; This is typically a one-off everytime we enter a room - so not time critical
; Similar to the room, we store (temporarily) the screen after the video buffer
; There is 1535 bytes left (and we only need up to 40*5=200 tiles -> 400 bytes)
push ax
push bx
push cx
push si
push di
push ds
mov bx, [VIDEO_BUFFER]
mov es, bx
mov bh, cl
; move the tile config to the end of buffer
; this is to avoid using 3 segment (video buffer + screen tiles config + tiles gfx)
; tile config is 20 * 10 bytes = 200 bytes (there is 65535 - 64000 = 1535 bytes left)
mov di, 320 * 200 + 600
; I need to multiply cl by 5 (since cl is at most 40 - it can be done on 8bits)
mov ch, cl
shl cl, 2
add cl, ch
xor ch, ch
rep movsw
; then we can
; this time, no need to store it. We can simply generate the sprite in the video buffer
mov ds, ax
mov si, 320 * 200 + 600
mov di, 320 * 160
add di, dx
; precalculate the return after each row
mov ax, 320
mov cl, bh
xor ch, ch
sub ax, cx
shl ax, 3
mov cl, 5
@@loop_sprite8_cols:
mov ch, bh
@@loop_sprite8_rows:
mov bl, es:[si]
call DISPLAY_SMALL_SPRITE
inc si
add di, 8
dec ch
jnz @@loop_sprite8_rows
add di, ax
dec cl
jnz @@loop_sprite8_cols
pop ds
pop di
pop si
pop cx
pop bx
pop ax
ret
GENERATE_QUESTIONAREA:
; Generate the question area - most of it is hardcoded here. Logic is similar to clue/password area
; This is typically a one-off everytime we find a password-locked room
push cx
push si
push di
push ds
push es
mov cx, VGA_RAM_LOCATION
mov es, cx
; move the tile config to the end of buffer
; this is to avoid using 3 segment (video buffer + screen tiles config + tiles gfx)
; tile config is 20 * 10 bytes = 200 bytes (there is 65535 - 64000 = 1535 bytes left)
mov si, offset QUESTIONAREA
mov di, 320 * 200 + 600
mov cx, 4 * 13
rep movsw
; then this time, no need to store it. We can simply generate the sprite in the video buffer
mov cx, [SCREEN_PTR+2]
mov ds, cx
mov si, 320 * 200 + 600
mov di, 108 + (60 * 320)
mov cl, 4
@@loop_sprite8_cols:
mov ch, 13
@@loop_sprite8_rows:
mov bl, es:[si]
call DISPLAY_SMALL_SPRITE
inc si
add di, 8
dec ch
jnz @@loop_sprite8_rows
add di, (320 * 8) - (8 * 13)
dec cl
jnz @@loop_sprite8_cols
pop es
pop ds
pop di
pop si
pop cx
ret
SET_ROOM_CLUE:
; Set the room clue - we need first to reset the clue area
pusha
push ds
pop es
mov si, offset ORIGINALCLUEAREA
mov di, offset CLUEAREA
mov cx, 27 * 5
rep movsb
; Then we can add the message
mov si, offset ROOM_CLUE
mov di, 28 + offset CLUEAREA
mov cl, 3
@@loop_cluearea_cols:
mov ch, 25
@@loop_cluearea_rows:
xor ah, ah
mov al, [si]
cmp al, 24h
jz @CLUE_AREA_DONE
mov bx, offset LETTER_MAPPING
sub ax, 20h
add bx, ax
mov al, [bx]
@@add_letter:
mov [di], al
inc si
inc di
dec ch
jnz @@loop_cluearea_rows
add di, 2
dec cl
jnz @@loop_cluearea_cols
@CLUE_AREA_DONE:
popa
ret
UPLOAD_CURRENT_ROOM:
pusha
push ds
pop es
; first update the original / target room
mov al, [ROOM_NUMBER]
dec al
; shift by x400 = x256 + x144 = x256 + x128 + x16
; x256 is easy since it means moving al to ah
mov ah, al
mov bl, al
xor al, al
xor bh, bh
shl bx, 7 ; x128
add ax, bx
shr bx, 3 ; /128 and x16, i.e. /8
add ax, bx
mov si, offset ALL_ROOMS_DATA
add si, ax
mov di, offset ORIGINALROOM
mov cx, 100
rep movsw
mov di, offset TARGETROOM
mov cx, 100
rep movsw
; copy over original room to current room
mov si, offset ORIGINALROOM
mov di, offset CURRENTROOM
mov cx, 100
rep movsw
; now all the room information
mov al, [ROOM_NUMBER]
dec al
; we need to multiply x85. This one is tricky = x64 + x21 = x64 + x16 + x4 + x1
xor ah, ah
mov bx, ax
shl ax, 6 ; x64
add ax, bx ; + x1
shl bx, 2
add ax, bx ; + x4
shl bx, 2
add ax, bx ; + x16
mov si, offset ALL_ROOMS_INFO
add si, ax
mov di, offset ROOM_FLAGS
mov cx, 85
rep movsb
popa
ret
SAVE_CURRENT_ROOM:
; this is basically the reverse of UPLOAD_CURRENT_ROOM - we essentially exchange si and di
; it stores the current room data, if we are leaving it
pusha
push ds
pop es