Revision | 6de6f2b684fa15f3629c8788979e38cca0111e48 (tree) |
---|---|
Time | 2020-01-01 17:36:02 |
Author | inglorion <homemicro@ingl...> |
Commiter | inglorion |
rom: added function table and more functions
@@ -2,6 +2,8 @@ | ||
2 | 2 | BUFPTR = $82 |
3 | 3 | SHOWADDR = $84 |
4 | 4 | SHOWCTR = $86 |
5 | + POLLKEYX = $f8 | |
6 | + POLLKEYY = $f9 | |
5 | 7 | PUTINTAD = $fa |
6 | 8 | PUTINTDG = $fb |
7 | 9 | PUTINTPS = $fc |
@@ -29,6 +31,33 @@ | ||
29 | 31 | |
30 | 32 | ;; ROM function jump table. |
31 | 33 | jmp cls |
34 | + jmp clshome | |
35 | + jmp showchr | |
36 | + jmp showspc | |
37 | + jmp show | |
38 | + jmp showint | |
39 | + jmp showuint | |
40 | + jmp newline | |
41 | + jmp setcur | |
42 | + jmp col0 | |
43 | + jmp scrollup | |
44 | + jmp loadcart | |
45 | + jmp savecart | |
46 | + jmp twistart | |
47 | + jmp twistop | |
48 | + jmp twiresta | |
49 | + jmp twisendb | |
50 | + jmp twigetb | |
51 | + jmp twiack | |
52 | + jmp twinak | |
53 | + jmp qkbrow | |
54 | + jmp pollkey | |
55 | + jmp pollchr | |
56 | + jmp waitkey | |
57 | + jmp waitchr | |
58 | + jmp shchr | |
59 | + jmp copy | |
60 | + jmp copy8 | |
32 | 61 | |
33 | 62 | .dsb FONTBASE-*, $ff |
34 | 63 | _charset: |
@@ -350,6 +379,13 @@ | ||
350 | 379 | bcc cls_loop1 |
351 | 380 | rts |
352 | 381 | |
382 | +clshome: | |
383 | +;;; Clears the screen and sets the cursor to 0, 0. | |
384 | + jsr cls | |
385 | + lda #0 | |
386 | + tax | |
387 | + jmp setcur | |
388 | + | |
353 | 389 | cmp16: |
354 | 390 | ;;; Compares two 16-bit numbers. |
355 | 391 | ;;; In: |
@@ -370,6 +406,54 @@ | ||
370 | 406 | sbc $a3 |
371 | 407 | rts |
372 | 408 | |
409 | +col0: | |
410 | +;;; Sets the cursor to column 0 on the current line. | |
411 | + ;; We find the line the cursor is on by starting at an address | |
412 | + ;; corresponding to line 25 (one after the last valid line), | |
413 | + ;; then moving up one line at a time until the address becomes | |
414 | + ;; less than or equal to the cursor position. There are 320 | |
415 | + ;; bytes in a line of text; we shift everything right 6 bits | |
416 | + ;; so that the size of our lines is 5. | |
417 | + ;; Instead of right shifting the cursos position 6 times, we | |
418 | + ;; left shift 2 times and use CURPOS + 1. | |
419 | + ;; line 3, column 7. | |
420 | + ;; 320 * 3 + 8 * 7 = 1016. + 8192 = 9208. $23f8 | |
421 | + ;; target: 960 + 8192 = 9152. $23c0 | |
422 | + asl CURPOS | |
423 | + rol CURPOS + 1 | |
424 | + ;; $47dc | |
425 | + asl CURPOS | |
426 | + rol CURPOS + 1 | |
427 | + ;; $8fb8 | |
428 | + ;; Starting position: (#$2000 + (25 * 320)) >> 6: $fd. | |
429 | + ;; We actually start 1 below that, to get the effect of a | |
430 | + ;; less-or-equal comparison instead of a less-than comparison. | |
431 | + lda #$fc | |
432 | +col0l: | |
433 | + cmp CURPOS + 1 | |
434 | + bcc col0c | |
435 | + sbc #5 ; Carry is set, so this subtracts 5. | |
436 | + ;; $8e | |
437 | + bcs col0l ; Always taken. | |
438 | +col0c: | |
439 | + adc #1 ; Carry is clear, so this adds 1. | |
440 | + ;; $8f | |
441 | + ;; The new cursor position should be a, shifted left 6 times. | |
442 | + ;; Instead, we shift right 2 times. | |
443 | + lsr | |
444 | + ;; $47 | |
445 | + ror CURPOS | |
446 | + ;; $80 | |
447 | + lsr | |
448 | + ;; $23 | |
449 | + sta CURPOS + 1 | |
450 | + lda CURPOS | |
451 | + ror | |
452 | + ;; $c0 | |
453 | + and #$c0 | |
454 | + sta CURPOS | |
455 | + rts | |
456 | + | |
373 | 457 | copy8: |
374 | 458 | ;;; Copies 8 bytes from ($a2,3) to ($a0,1). |
375 | 459 | ;;; Clobbers y. |
@@ -383,6 +467,105 @@ | ||
383 | 467 | bne copy |
384 | 468 | rts |
385 | 469 | |
470 | +newline: | |
471 | + jsr col0 | |
472 | + lda CURPOS | |
473 | + clc | |
474 | + adc #$40 | |
475 | + sta CURPOS | |
476 | + lda CURPOS + 1 | |
477 | + adc #1 | |
478 | + sta CURPOS + 1 | |
479 | + jmp adjcur | |
480 | + | |
481 | +pollchr: | |
482 | +;;; Polls the keyboard as per pollkey. If a key press was | |
483 | +;;; detected, the shift state is used to shift the return | |
484 | +;;; value as appropriate. | |
485 | +;;; Out: | |
486 | +;;; a character, or 0 if no key press. | |
487 | +;;; Clobbers: x, y. | |
488 | + jsr pollkey | |
489 | + beq pollchrd | |
490 | + tax | |
491 | + lda KBDSTATE + 2 | |
492 | + and #$80 | |
493 | + bne pollchrn | |
494 | + txa | |
495 | + jsr shchr | |
496 | + tax | |
497 | +pollchrn: | |
498 | + txa | |
499 | +pollchrd: | |
500 | + rts | |
501 | + | |
502 | +pollkey: | |
503 | +;;; Polls the keyboard for new key presses. | |
504 | +;;; KBDSTATE is updated to reflect any keys that were | |
505 | +;;; released. | |
506 | +;;; If any keys were pressed since the last update | |
507 | +;;; to KBDSTATE, one key is chosen, it is recorded | |
508 | +;;; as pressed, and its code is returned. | |
509 | +;;; Out: | |
510 | +;;; a If a keypress was detected, the key code. | |
511 | +;;; If no keypress was detected, 0. | |
512 | +;;; Clobbers x, y. | |
513 | + ldy #7 | |
514 | + lda #$80 | |
515 | + sta POLLKEYX | |
516 | + lda #$7f | |
517 | + sta POLLKEYY | |
518 | +pollkeyl: | |
519 | + sta KBDROW | |
520 | + nop | |
521 | + lda KBDCOL | |
522 | + tax | |
523 | + ora KBDSTATE, y | |
524 | + sta KBDSTATE, y | |
525 | + txa | |
526 | + eor KBDSTATE, y | |
527 | + beq pollkeyn | |
528 | + ;; Key pressed. | |
529 | + ;; If we already recorded a key, do nothing. | |
530 | + ldx POLLKEYX | |
531 | + bpl pollkeyn | |
532 | + ;; Pick one bit in a that's nonzero. | |
533 | + sta POLLKEYX | |
534 | + lda #$80 | |
535 | + ldx #7 | |
536 | +pollkeyb: | |
537 | + asl POLLKEYX | |
538 | + bcs pollkeyf | |
539 | + dex | |
540 | + lsr | |
541 | + bne pollkeyb | |
542 | +pollkeyf: | |
543 | + ;; Store that bit in POLLKEYX. | |
544 | + stx POLLKEYX | |
545 | + ;; Flip that bit in KBDSTATE, y. | |
546 | + eor KBDSTATE, y | |
547 | + sta KBDSTATE, y | |
548 | + ;; Encode row in $b1, too. | |
549 | + tya | |
550 | + asl | |
551 | + asl | |
552 | + asl | |
553 | + ora POLLKEYX | |
554 | + sta POLLKEYX | |
555 | +pollkeyn: | |
556 | + sec | |
557 | + ror POLLKEYY | |
558 | + lda POLLKEYY | |
559 | + dey | |
560 | + bpl pollkeyl | |
561 | + ldy POLLKEYX | |
562 | + bpl pollkeym | |
563 | + lda #0 | |
564 | + rts | |
565 | +pollkeym: | |
566 | + lda kbmap, y | |
567 | + rts | |
568 | + | |
386 | 569 | putint: |
387 | 570 | ;; In: |
388 | 571 | ;; $a0..$a1 value to convert. |
@@ -507,6 +690,10 @@ | ||
507 | 690 | lda KBDCOL |
508 | 691 | rts |
509 | 692 | |
693 | +savecart: | |
694 | + ;; TODO: Implement. | |
695 | + rts | |
696 | + | |
510 | 697 | sub16: |
511 | 698 | sec |
512 | 699 | sbc16: |
@@ -648,6 +835,43 @@ | ||
648 | 835 | sta $81 |
649 | 836 | rts |
650 | 837 | |
838 | +shchr: | |
839 | +;;; Convert unshifted character code to shifted character code. | |
840 | +;;; For example, 'a' becomes 'A', '1' becomes '!'. | |
841 | +;;; In: | |
842 | +;;; a character code | |
843 | +;;; Out: | |
844 | +;;; a shifted character code | |
845 | +;;; Clobbers y. | |
846 | + cmp #$27 | |
847 | + beq shchrq | |
848 | + cmp #$3d | |
849 | + beq shchre | |
850 | + cmp #$60 | |
851 | + beq shchrb | |
852 | + cmp #$41 | |
853 | + bcs shchrl | |
854 | + cmp #$21 | |
855 | + bcs shchry | |
856 | + rts | |
857 | +shchrq: | |
858 | + lda #$22 | |
859 | + rts | |
860 | +shchre: | |
861 | + lda #$2b | |
862 | + rts | |
863 | +shchrb: | |
864 | + lda #$7e | |
865 | + rts | |
866 | +shchrl: | |
867 | + eor #$20 | |
868 | + rts | |
869 | +shchry: | |
870 | + and #$0f | |
871 | + tay | |
872 | + lda shchrt, y | |
873 | + rts | |
874 | + | |
651 | 875 | show: |
652 | 876 | ;;; Displays a number of characters. |
653 | 877 | ;;; In: |
@@ -899,6 +1123,16 @@ | ||
899 | 1123 | sta SERCR |
900 | 1124 | rts |
901 | 1125 | |
1126 | +waitchr: | |
1127 | + jsr pollchr | |
1128 | + beq waitchr | |
1129 | + rts | |
1130 | + | |
1131 | +waitkey: | |
1132 | + jsr pollkey | |
1133 | + beq waitkey | |
1134 | + rts | |
1135 | + | |
902 | 1136 | _end: |
903 | 1137 | jmp _end |
904 | 1138 |
@@ -915,6 +1149,9 @@ | ||
915 | 1149 | .byt "'",$0d,"lkijm",$00 |
916 | 1150 | .byt "./;",$1e,$1c,$1d,$1f,$00 |
917 | 1151 | |
1152 | +shchrt: | |
1153 | + .byt ")!@#$%",$5e,"&*( :<_>?" | |
1154 | + | |
918 | 1155 | uinttbl: .word 80, 800, 8000, 40000 |
919 | 1156 | |
920 | 1157 | .dsb $fffa-*,$ff |