Calculator Community > [DE] Andere Programmierthemen und -hilfe |
Programm um Texte anzuzeigen. |
(1/1) |
MrApplecraft:
Hi Leute, vor einiger Zeit hab ich angefangen Assembler zu lernen und wollte jetzt ein Programm programmieren, das mir "Karten" anzeigt, die man umblättern kann. Leider ist mir ürgentwann aufgefallen wie groß der Code wird, hat jemand Tipps wie man den kleiner bekommt und den Text in einen Buffer bekommt? --- Code: ---KeyLoop: ld a, $FF ;Reset the keypad. out (1), a ld a, $FE ;Select group. out (1), a in a, (1) ;Test for keys. cp $FD jr z, Butleft cp $FB jr z, Butright ld a, $FF ;Reset the keypad. out (1), a ld a, $FD ;Select group. out (1), a in a, (1) ;Test for keys. cp $BF jr z, Getthehelloutofhere jr KeyLoop Butright: ld a,b cp 3 ; Don't increment B if it's at its maximum value. jr z, KeyLoop ;Gerade 3 Weil wir nicht mehr als 2 tabs haben inc B cp 2 jp z,Txt2 jp KeyLoop Butleft: ld a,b cp 0 ; Don't decrement B if it's at its minimum value. jr z, KeyLoop dec b cp 1 jp z,About jp KeyLoop Getthehelloutofhere: call _GrBufClr call _bufclear call _homeup call _clrscrnfull call _eraseeol ret ;Txt2 ;Draws first "Tab" Txt2: push bc ld hl,Texteins1 call Drawsmalltext call Deinvert ld hl,Texteins2 call Drawsmalltext ld hl,Texteins3 call Drawsmalltext ld hl,Texteins4 call Drawsmalltext ld hl,Texteins5 call Drawsmalltext ld hl,Texteins6 call Drawsmalltext ld hl,Texteins7 call Drawsmalltext ld hl,Texteins8 call Drawsmalltext ld hl,Texteins9 call Drawsmalltext ld hl,Texteins10 call Drawsmalltext pop bc jp KeyLoop ;About ;Draws the Text for the Aboutscreen About: push BC call Rahmen ld a,$0C call FastHorizLine ld a,$0D call FastHorizLine call _GRBUFCPY pop BC call Invert push bc ld d,0 ld b,0 ld hl,Abouttxt1 call Drawsmalltext ld b,$06 ld hl,Abouttxt2 call Drawsmalltext call Deinvert ld b,$02 ld a,$02 call LoadintoD ld hl,Abouttxt3 call Drawsmalltext ld hl,Abouttxt4 call Drawsmalltext ld hl,Abouttxt5 call Drawsmalltext ld hl,Abouttxt6 call Drawsmalltext ld a,$12 call LoadintoD ld hl,Abouttxt7 call Drawsmalltext pop bc jp KeyLoop ;Drawsmalltext ;Input: Pointer to text in HL ;Input: PenRow in D ;Input: PenCol in B ;Output: $06 added to D, Displays HL ;Destroys: ? Drawsmalltext: ld a,d ld (PENROW),a ld a,b ld (PENCOL),a push de call _vputs pop de ld a,$06 call LoadintoD ret ;LoadintoD ;Input: A ;Output: Adds A to D LoadintoD: add a,d ld d,a ret Invert: set textInverse, (iy+textflags) ret Deinvert: res textInverse, (iy+textflags) ret Texteins1: .db " Text",0 Texteins2: .db "Text2",0 Texteins3: .db "Text3",0 Texteins4: .db "Text4",0 Texteins5: .db "Text5",0 Texteins6: .db "Text6",0 Texteins7: .db "Text7",0 Texteins8: .db "Text8",0 Texteins9: .db "Text9",0 Texteins10: .db "Text10",0 .end --- End code --- |
Sorunome:
Hall MrApplecraft, wilkommen auf Omnimaga! Wenn ichs richtig verstanden habe suchst du eine allgemeine Methode wie du einen bestimmten text aus der Liste anzeigen kannst, trotz der verschiedenen Längen, ist das richtig? Ich würde es so machen dass ich ne liste an pointern zu den texten erstelle... --- Code: ---Texte: .dw Texteins1,Texteins2,Texteins3,Texteins4, [...] Texteins1: .db " Text",0 Texteins2: .db "Text2",0 Texteins3: .db "Text3",0 Texteins4: .db "Text4",0 Texteins5: .db "Text5",0 Texteins6: .db "Text6",0 Texteins7: .db "Text7",0 Texteins8: .db "Text8",0 Texteins9: .db "Text9",0 Texteins10: .db "Text10",0 --- End code --- Dann kannst du, wenn in 'a' jetzt die zahl ist, startend bei null, also 0 = Texteins1, 1 = Texteins2 usw. den pointer zum text so kriegen: --- Code: ---; erstmal tun wir den index von a in hl und multiplizieren ihn dann mit zwei, da ein pointer zwei byte groß ist ld h,0 ld l,a add hl,hl ; jetzt addieren wir den texte offset hinzu ld de,Texte add hl,de ; nun ist in hl ein pointer zum pointer vom text, also tun wir ihn in de und dann in hl per 'ex de,hl' ld e,(hl) inc hl ld d,(hl) ex de,hl ; jetzt ist der pointer zum text in hl --- End code --- Ich kenne mich nicht so sehr mit dem TIOS aus aber nach wikiti sollte bcall(_VPutS) gerade den pointer in hl wollen, also genau das was diese routine dir gibt. Ich hoffe ich konnte dir helfen, zögere nicht zu fragen wenn du etwas nicht verstehst ^.^ EDIT: ich hab grad das hier in deinem code gesehen: --- Code: --- call _eraseeol ret --- End code --- Das könnte optimiert werden zu --- Code: --- jp _eraseeol --- End code --- Das ist ein byte kleiner und 17cc schneller! Falls das label dicht genug dran ist kannst du natürlich auch jr anstelle von jp verenden. Das ist die sogenannte "tail-end optimization", wenn du einen call direkt gefolgt von ret hast ists das selbe als ob du einfach zu dem label hinspringst. EDIT2: ich habe gerade --- Code: --- cp 0 ; Don't decrement B if it's at its minimum value. --- End code --- gesehen. "or a" ist ein byte kleiner als "cp 0" und macht immer genau das selbe ^.^ |
MrApplecraft:
Danke für die Verbesserungsvorschläge und Hilfe. Gerade bin ich ürgentwie zu doof um ne Routine zu machen. --- Code: ---;Txt2 ;Draws second "Tab" Txt2: push bc call Invert call Rahmen ld hl,Titel1 call Drawsmalltext call Deinvert ld a,$00 ld e,$0A push de call LoadNewText pop bc jp KeyLoop Drawframe: ld a,$0 call FastVerticalLine ld a,$5F call FastVerticalLine ld a,$3F call FastHorizLine call _GRBUFCPY ret Rahmen: call _GrBufClr call _clrlcdfull call Drawframe call Invert ld d,$00 ld b,$01 ret LoadNewTextinca: push de inc a LoadNewText: ; erstmal tun wir den index von a in hl und multiplizieren ihn dann mit zwei, da ein pointer zwei byte groß ist ld h,0 ld l,a push af add hl,hl ; jetzt addieren wir den texte offset hinzu ld de,Texte add hl,de ; nun ist in hl ein pointer zum pointer vom text, also tun wir ihn in de und dann in hl per 'ex de,hl' ld e,(hl) inc hl ld d,(hl) ex de,hl pop de call Drawsmalltext pop af pop de cp a,e jr nz,LoadNewTextinca ret ;Drawsmalltext ;Input: Pointer to text in HL ;Input: PenRow in D ;Input: PenCol in B ;Output: $06 added to D, Displays HL ;Destroys: ? Drawsmalltext: ld a,d ld (PENROW),a ld a,b ld (PENCOL),a push de call _vputs pop de ld a,$06 call LoadintoD ret ;LoadintoD ;Input: A ;Output: Adds A to D LoadintoD: add a,d ld d,a ret ;FastVerticalLine ;Input: A ;Output: Vertical line at A ;Destroys: af,bc,de,hl FastVerticalLine: push bc push de ld hl,plotsscreen ld d,0 ld e,a srl e srl e srl e add hl,de and $07 ld b,a inc b ld a,1 vertloop1: rrca djnz vertloop1 ld c,a ld b,64 ld e,12 vertloop2: ld a,c or (hl) ld (hl),a add hl,de djnz vertloop2 pop bc pop de ret ;FastHorizLine ;Input: A ;Output: Horizontal line at A ;Destroys: HL,BC FastHorizLine: push bc ld l,a ld h,0 add a,a add a,l ld l,a add hl,hl add hl,hl ld bc,plotsscreen add hl,bc ld b,12 horizloop: ld (hl),%11111111 inc hl djnz horizloop pop bc ret --- End code --- EDIT: Es handelt sich um die Loadnewtext routine. |
Sorunome:
--- Code: ---LoadNewTextinca: push de inc a LoadNewText: ; erstmal tun wir den index von a in hl und multiplizieren ihn dann mit zwei, da ein pointer zwei byte groß ist ld h,0 ld l,a push af add hl,hl ; jetzt addieren wir den texte offset hinzu ld de,Texte add hl,de ; nun ist in hl ein pointer zum pointer vom text, also tun wir ihn in de und dann in hl per 'ex de,hl' ld e,(hl) inc hl ld d,(hl) ex de,hl pop de call Drawsmalltext pop af pop de cp a,e jr nz,LoadNewTextinca ret --- End code --- Wenn du "LoadNewText" direkt aufrufst dann passiert nie "push de", und somit hat dann dein program unerwartete effekte, da du dann im ersten "pop de" anstelle davon de wiederherzustellen die addresse von LoadNewText lädst. Und die reinfolge in der du af und de speicherst / wiederherstellst ist auch wichtig Du könntest sowas ausprobieren (untested): --- Code: ---LoadNewText: push de push af push de ; erstmal tun wir den index von a in hl und multiplizieren ihn dann mit zwei, da ein pointer zwei byte groß ist ld h,0 ld l,a add hl,hl ; jetzt addieren wir den texte offset hinzu ld de,Texte add hl,de ; nun ist in hl ein pointer zum pointer vom text, also tun wir ihn in de und dann in hl per 'ex de,hl' ld e,(hl) inc hl ld d,(hl) ex de,hl pop de call Drawsmalltext pop af pop de cp a,e ret z LoadNewTextinca: inc a jr LoadNewText --- End code --- EDIT: hab code beispiel repariert, ich hatte übersehen dass deine push/pop's nicht gematched sind |
Navigation |
Message Index |