diff --git a/CPUCore.pas b/CPUCore.pas index 30c1b6f..101ca91 100644 --- a/CPUCore.pas +++ b/CPUCore.pas @@ -21,13 +21,15 @@ type end; TCPUCellState = ( - cs_implemen, //Implemented. Can be used. + cs_impleSFR, //Implemented. Used by Oeprative System o Kernel + cs_impleGPR, //Implemented. Can be used. cs_unimplem //Not implemented. ); TCPURamUsed = ( - ruUnused, - ruCode, //Used for code - ruVar //Used for variable + ruUnused, //(NOT included in PRG output file) + ruCode, //Used for code (included in PRG output file) + ruData, //Used for variables (included in PRG output file) + ruAbsData //Used for variables in absolute positions (NOT included in PRG output file) ); type //Models for RAM memory @@ -103,6 +105,7 @@ type procedure DisableAllRAM; procedure SetStatRAM(i1, i2: word; status0: TCPUCellState); function SetStatRAMCom(strDef: string): boolean; + function SetDataAddr(strDef: string): boolean; function HaveConsecRAM(const i, n: word; maxRam: dword): boolean; //Indica si hay "n" bytes libres procedure UseConsecRAM(const i, n: word); //Ocupa "n" bytes en la posición "i" procedure SetSharedUnused; @@ -148,7 +151,7 @@ end; function TCPURamCell.Avail: boolean; {Indica si el registro es una dirección disponible en la memoria RAM.} begin - Result := (state = cs_implemen); + Result := (state = cs_impleGPR); end; { TCPUCore } @@ -239,10 +242,10 @@ begin end; staMem := copy(com, 9, 3); case staMem of - 'IMP': state := cs_implemen; + 'IMP': state := cs_impleGPR; 'NIM': state := cs_unimplem; else - MsjError := 'Memory definition syntax error: Expected SFR or GPR'; + MsjError := 'Memory definition syntax error: Expected IMP or NIM'; exit(false); end; //Ya se tienen los parámetros, para definir la memoria @@ -251,6 +254,10 @@ begin finally coms.Destroy; end; +end; +function TCPUCore.SetDataAddr(strDef: string): boolean; +begin + end; function TCPUCore.HaveConsecRAM(const i, n: word; maxRam: dword): boolean; {Indica si hay "n" bytes consecutivos libres en la posicióm "i", en RAM. @@ -263,7 +270,7 @@ begin c := 0; j := i; while (j<=maxRam) and (c cs_implemen) or (ram[j].used<>ruUnused) then exit; + if (ram[j].state <> cs_impleGPR) or (ram[j].used<>ruUnused) then exit; inc(c); //verifica siguiente inc(j); end; @@ -278,7 +285,7 @@ procedure TCPUCore.UseConsecRAM(const i, n: word); var j: word; begin for j:=i to i+n-1 do begin - ram[j].used := ruVar; //todos los bits + ram[j].used := ruData; //todos los bits end; end; procedure TCPUCore.SetSharedUnused; @@ -287,7 +294,7 @@ var i: Integer; begin for i:=0 to high(ram) do begin - if (ram[i].state = cs_implemen) and (ram[i].shared) then begin + if (ram[i].shared) and (ram[i].state = cs_impleGPR) then begin ram[i].used := ruUnused; end; end; @@ -298,8 +305,8 @@ var i: Integer; begin for i:=0 to high(ram) do begin - if (ram[i].state = cs_implemen) and (ram[i].shared) then begin - ram[i].used := ruVar; //Set as used for variables + if (ram[i].shared) and (ram[i].state = cs_impleGPR) then begin + ram[i].used := ruData; //Set as used for variables end; end; end; @@ -354,6 +361,7 @@ end; procedure TCPUCore.addTopComm(comm: string; replace: boolean); {Agrega un comentario de línea al código en la posición de memoria actual} begin + if iRam>=CPUMAXRAM then exit; if replace then begin ram[iRam].topComment := comm; end else begin diff --git a/Cambios.txt b/Cambios.txt index e3026d9..8d4a8d8 100644 --- a/Cambios.txt +++ b/Cambios.txt @@ -3,6 +3,7 @@ Se cambian variables a tipo dword para evitar desborde en TP6502.GetFreeBytes(). Se cambia el tipo del campo TCPURamCell.used al enumerado TCPURamUsed, para dar más libertad para definir a la RAM. +Se agrega un estado más para la memoria RAM. 0.1 === diff --git a/MiniAssembler/project1.exe.hex b/MiniAssembler/project1.exe.hex index 269f46c..8492709 100644 Binary files a/MiniAssembler/project1.exe.hex and b/MiniAssembler/project1.exe.hex differ diff --git a/MiniAssembler/project1.lpi b/MiniAssembler/project1.lpi index a32364f..11c0dcf 100644 --- a/MiniAssembler/project1.lpi +++ b/MiniAssembler/project1.lpi @@ -1,7 +1,7 @@ - + @@ -9,7 +9,6 @@ <ResourceType Value="res"/> <UseXPManifest Value="True"/> - <Icon Value="0"/> </General> <i18n> <EnableI18N LFM="False"/> @@ -21,9 +20,10 @@ <Version Value="2"/> </PublishOptions> <RunParams> - <local> - <FormatVersion Value="1"/> - </local> + <FormatVersion Value="2"/> + <Modes Count="1"> + <Mode0 Name="default"/> + </Modes> </RunParams> <RequiredPackages Count="1"> <Item1> diff --git a/MiniAssembler/project1.lps b/MiniAssembler/project1.lps index 57e7208..5013d65 100644 --- a/MiniAssembler/project1.lps +++ b/MiniAssembler/project1.lps @@ -2,7 +2,7 @@ <CONFIG> <ProjectSession> <PathDelim Value="\"/> - <Version Value="10"/> + <Version Value="11"/> <BuildModes Active="Default"/> <Units Count="5"> <Unit0> @@ -12,7 +12,7 @@ <WindowIndex Value="-1"/> <TopLine Value="-1"/> <CursorPos X="-1" Y="-1"/> - <UsageCount Value="60"/> + <UsageCount Value="61"/> </Unit0> <Unit1> <Filename Value="unit1.pas"/> @@ -21,19 +21,18 @@ <HasResources Value="True"/> <ResourceBaseClass Value="Form"/> <UnitName Value="Unit1"/> - <TopLine Value="152"/> - <CursorPos Y="171"/> - <UsageCount Value="60"/> + <IsVisibleTab Value="True"/> + <TopLine Value="135"/> + <CursorPos X="20" Y="154"/> + <UsageCount Value="61"/> <Loaded Value="True"/> <LoadedDesigner Value="True"/> </Unit1> <Unit2> <Filename Value="..\P6502utils.pas"/> - <IsVisibleTab Value="True"/> <EditorIndex Value="1"/> - <TopLine Value="1115"/> - <CursorPos X="24" Y="1136"/> - <FoldState Value=" TL00C1414113 T5J0{W111 TCjEK5 T7jPJC T8jQ26132 T3m8051]ZD2]E0nFD7I2K T6n601]gHnEF%2L"/> + <TopLine Value="178"/> + <CursorPos X="15" Y="202"/> <UsageCount Value="32"/> <Bookmarks Count="1"> <Item0 Y="1211" ID="1"/> @@ -43,9 +42,8 @@ <Unit3> <Filename Value="..\CPUCore.pas"/> <EditorIndex Value="2"/> - <TopLine Value="37"/> - <CursorPos X="42" Y="88"/> - <FoldState Value=" TL0040211193 T4801 T5A[64CED8 T7dC6 T8iE230122145 T3kX0331]mHl8B4]i6lI01A T0leR3C pjAjYN3857 TDmZ2e]ZEnU]+'"/> + <TopLine Value="98"/> + <CursorPos X="31" Y="121"/> <UsageCount Value="25"/> <Bookmarks Count="1"> <Item0 Y="117" ID="3"/> @@ -60,122 +58,124 @@ <UsageCount Value="10"/> </Unit4> </Units> - <JumpHistory Count="30" HistoryIndex="29"> + <JumpHistory Count="29" HistoryIndex="28"> <Position1> <Filename Value="..\p6502utils.pas"/> - <Caret Line="363" Column="17" TopLine="254"/> + <Caret Line="259" Column="21" TopLine="218"/> </Position1> <Position2> <Filename Value="..\p6502utils.pas"/> + <Caret Line="355" Column="65" TopLine="252"/> </Position2> <Position3> <Filename Value="..\p6502utils.pas"/> - <Caret Line="226" TopLine="211"/> + <Caret Line="368" Column="5" TopLine="265"/> </Position3> <Position4> <Filename Value="..\p6502utils.pas"/> + <Caret Line="373" Column="32" TopLine="265"/> </Position4> <Position5> <Filename Value="..\p6502utils.pas"/> - <Caret Line="259" Column="21" TopLine="218"/> + <Caret Line="1060" Column="49" TopLine="963"/> </Position5> <Position6> <Filename Value="..\p6502utils.pas"/> - <Caret Line="355" Column="65" TopLine="252"/> + <Caret Line="1085" Column="49" TopLine="1064"/> </Position6> <Position7> <Filename Value="..\p6502utils.pas"/> - <Caret Line="368" Column="5" TopLine="265"/> </Position7> <Position8> <Filename Value="..\p6502utils.pas"/> - <Caret Line="373" Column="32" TopLine="265"/> + <Caret Line="370" Column="8" TopLine="354"/> </Position8> <Position9> <Filename Value="..\p6502utils.pas"/> - <Caret Line="1060" Column="49" TopLine="963"/> + <Caret Line="369" Column="28" TopLine="354"/> </Position9> <Position10> <Filename Value="..\p6502utils.pas"/> - <Caret Line="1085" Column="49" TopLine="1064"/> + <Caret Line="1148" TopLine="1141"/> </Position10> <Position11> <Filename Value="..\p6502utils.pas"/> + <Caret Line="207" Column="33" TopLine="180"/> </Position11> <Position12> <Filename Value="..\p6502utils.pas"/> - <Caret Line="370" Column="8" TopLine="354"/> </Position12> <Position13> <Filename Value="..\p6502utils.pas"/> - <Caret Line="369" Column="28" TopLine="354"/> + <Caret Line="1077" Column="62" TopLine="957"/> </Position13> <Position14> <Filename Value="..\p6502utils.pas"/> - <Caret Line="1148" TopLine="1141"/> + <Caret Line="1446" Column="12" TopLine="1155"/> </Position14> <Position15> - <Filename Value="..\p6502utils.pas"/> - <Caret Line="207" Column="33" TopLine="180"/> - </Position15> - <Position16> - <Filename Value="..\p6502utils.pas"/> - </Position16> - <Position17> - <Filename Value="..\p6502utils.pas"/> - <Caret Line="1077" Column="62" TopLine="957"/> - </Position17> - <Position18> - <Filename Value="..\p6502utils.pas"/> - <Caret Line="1446" Column="12" TopLine="1155"/> - </Position18> - <Position19> <Filename Value="..\CPUCore.pas"/> <Caret Line="155" Column="6" TopLine="121"/> - </Position19> - <Position20> + </Position15> + <Position16> <Filename Value="..\P6502utils.pas"/> <Caret Line="152" Column="18"/> + </Position16> + <Position17> + <Filename Value="..\P6502utils.pas"/> + <Caret Line="19" Column="38"/> + </Position17> + <Position18> + <Filename Value="..\P6502utils.pas"/> + <Caret Line="144" Column="26" TopLine="20"/> + </Position18> + <Position19> + <Filename Value="..\P6502utils.pas"/> + <Caret Line="201" Column="42" TopLine="180"/> + </Position19> + <Position20> + <Filename Value="..\CPUCore.pas"/> + <Caret Line="88" Column="3" TopLine="71"/> </Position20> <Position21> <Filename Value="..\P6502utils.pas"/> - <Caret Line="19" Column="38"/> + <Caret Line="1129" Column="48" TopLine="1113"/> </Position21> <Position22> - <Filename Value="..\P6502utils.pas"/> - <Caret Line="144" Column="26" TopLine="20"/> - </Position22> - <Position23> - <Filename Value="..\P6502utils.pas"/> - <Caret Line="201" Column="42" TopLine="180"/> - </Position23> - <Position24> - <Filename Value="..\CPUCore.pas"/> - <Caret Line="88" Column="3" TopLine="71"/> - </Position24> - <Position25> - <Filename Value="..\P6502utils.pas"/> - <Caret Line="1129" Column="48" TopLine="1113"/> - </Position25> - <Position26> <Filename Value="..\CPUCore.pas"/> <Caret Line="88" Column="16" TopLine="71"/> + </Position22> + <Position23> + <Filename Value="..\CPUCore.pas"/> + </Position23> + <Position24> + <Filename Value="..\P6502utils.pas"/> + <Caret Line="1129" Column="48" TopLine="1113"/> + </Position24> + <Position25> + <Filename Value="..\CPUCore.pas"/> + <Caret Line="88" Column="42" TopLine="37"/> + </Position25> + <Position26> + <Filename Value="..\P6502utils.pas"/> + <Caret Line="1134" Column="7" TopLine="1115"/> </Position26> <Position27> <Filename Value="..\CPUCore.pas"/> + <Caret Line="64" Column="24" TopLine="37"/> </Position27> <Position28> <Filename Value="..\P6502utils.pas"/> - <Caret Line="1129" Column="48" TopLine="1113"/> + <Caret Line="1172" Column="12" TopLine="1150"/> </Position28> <Position29> - <Filename Value="..\CPUCore.pas"/> - <Caret Line="88" Column="42" TopLine="37"/> + <Filename Value="unit1.pas"/> + <Caret Line="131" Column="18" TopLine="113"/> </Position29> - <Position30> - <Filename Value="..\P6502utils.pas"/> - <Caret Line="1134" Column="7" TopLine="1115"/> - </Position30> </JumpHistory> + <RunParams> + <FormatVersion Value="2"/> + <Modes Count="0" ActiveMode="default"/> + </RunParams> </ProjectSession> </CONFIG> diff --git a/MiniAssembler/project1.res b/MiniAssembler/project1.res index bc23f8c..0ad004b 100644 Binary files a/MiniAssembler/project1.res and b/MiniAssembler/project1.res differ diff --git a/MiniAssembler/unit1.lfm b/MiniAssembler/unit1.lfm index 637ca93..37c059b 100644 --- a/MiniAssembler/unit1.lfm +++ b/MiniAssembler/unit1.lfm @@ -8,7 +8,7 @@ object Form1: TForm1 ClientWidth = 530 OnCreate = FormCreate OnDestroy = FormDestroy - LCLVersion = '1.8.0.6' + LCLVersion = '2.0.0.4' object Memo1: TMemo Left = 10 Height = 312 diff --git a/MiniAssembler/unit1.pas b/MiniAssembler/unit1.pas index 7ca83f1..36622aa 100644 --- a/MiniAssembler/unit1.pas +++ b/MiniAssembler/unit1.pas @@ -128,7 +128,7 @@ begin //Extract parameters if l = '' then begin //No parameters. Must be Implicit - pic.codAsmFD(idInst, aImplicit , 0); + pic.codAsm(idInst, aImplicit , 0); if pic.MsjError<>'' then begin Application.MessageBox(PChar(lin + ':' + pic.MsjError),''); exit; @@ -137,7 +137,7 @@ begin //It's a string if Par = 'A' then begin //Accumulator mode - pic.codAsmFD(idInst, aAcumulat , 0); + pic.codAsm(idInst, aAcumulat , 0); if pic.MsjError<>'' then begin Application.MessageBox(PChar(lin + ':' + pic.MsjError),''); exit; @@ -149,14 +149,14 @@ begin //There is a number if n<256 then begin //Zero page. Although could be ,X - pic.codAsmFD(idInst, aZeroPage , 0); + pic.codAsm(idInst, aZeroPage , 0); if pic.MsjError<>'' then begin Application.MessageBox(PChar(lin + ':' + pic.MsjError),''); exit; end; end else begin //Absolute. Although could be ,X - pic.codAsmFD(idInst, aAbsolute , 0); + pic.codAsm(idInst, aAbsolute , 0); if pic.MsjError<>'' then begin Application.MessageBox(PChar(lin + ':' + pic.MsjError),''); exit; diff --git a/P6502utils.pas b/P6502utils.pas index 4989de8..ae472ed 100644 --- a/P6502utils.pas +++ b/P6502utils.pas @@ -190,8 +190,8 @@ type function DisassemblerAt(addr: word; out nBytesProc: byte; useVarName: boolean ): string; override; public //RAM memory functions - function GetFreeByte(out addr: word; shared: boolean): boolean; - function GetFreeBytes(const size: integer; var addr: word): boolean; //obtiene una dirección libre + function GetFreeByte(out addr: word): boolean; + function GetFreeBytes(const size: integer; out addr: word): boolean; //obtiene una dirección libre function TotalMemRAM: integer; //devuelve el total de memoria RAM function UsedMemRAM: word; //devuelve el total de memoria RAM usada procedure ExploreUsed(rutExplorRAM: TCPURutExplorRAM); //devuelve un reporte del uso de la RAM @@ -265,7 +265,7 @@ begin end; ram[iRam].value := value; if isData then ram[iRam].name := 'data'; - ram[iRam].used := ruVar; //marca como usado + ram[iRam].used := ruData; //marca como usado inc(iRam); end; procedure TP6502.codAsm(const inst: TP6502Inst; addMode: TP6502AddMode; param: word); @@ -668,7 +668,9 @@ begin i_BEQ:; //branch on equal (zero set) i_BIT:; //bit test i_BMI:; //branch on minus (negative set) - i_BNE:; //branch on not equal (zero clear) + i_BNE: begin + + end; //branch on not equal (zero clear) i_BPL:; //branch on plus (negative clear) i_BRK:; //break / interrupt i_BVC:; //branch on overflow clear @@ -1138,7 +1140,7 @@ begin PC.W := AValue; end; //Funciones para la memoria RAM -function TP6502.GetFreeByte(out addr: word; shared: boolean): boolean; +function TP6502.GetFreeByte(out addr: word): boolean; {Devuelve una dirección libre de la memoria RAM, a partir de la dirección iRam. "Shared" indica que se marcará el bit como de tipo "Compartido", y se usa para el caso en que se quiera comaprtir la misma posición para diversos variables. @@ -1151,12 +1153,12 @@ begin maxRam := CPUMAXRAM; //posición máxima //Realmente debería explorar solo hasta la dirección implementada, por eficiencia for i:=iRam to maxRam-1 do begin - if (ram[i].state = cs_implemen) and (ram[i].used = ruUnused) then begin + if (ram[i].state = cs_impleGPR) and (ram[i].used = ruUnused) then begin //Esta dirección está libre - ram[i].used := ruVar; //marca como usado para variable - if shared then begin - ram[i].shared := true; //Marca como compartido - end; +// ram[i].used := ruData; //marca como usado para variable +// if shared then begin +// ram[i].shared := true; //Marca como compartido +// end; addr := i; //Notar que la posición de memoria puede estar mapeada. Result := true; //indica que encontró espacio @@ -1164,24 +1166,25 @@ begin end; end; end; -function TP6502.GetFreeBytes(const size: integer; var addr: word): boolean; -{Devuelve una dirección libre de la memoria RAM para ubicar un bloque - del tamaño indicado. Si encuentra espacio, devuelve TRUE. - El tamaño se da en bytes, pero si el valor es negativo, se entiende que es en bits.} +function TP6502.GetFreeBytes(const size: integer; out addr: word): boolean; +{Returns a free memory address of RAM to locate a block of the specified size (in bytes). + If found returns TRUE. } var i: dword; maxRam: dWord; begin Result := false; //valor por defecto - if size=0 then exit; + if size=0 then begin + addr := 0; + exit(true); + end; maxRam := CPUMAXRAM; for i:=iRam to maxRam-1 do begin //verifica 1 a 1, por seguridad if HaveConsecRAM(i, size, maxRam) then begin //encontró del tamaño buscado - UseConsecRAM(i, size); //marca como usado + //UseConsecRAM(i, size); //marca como usado addr := i; - Result := true; //indica que encontró espacio - exit; + exit(true); end; end; end; @@ -1222,7 +1225,7 @@ begin end; end; function TP6502.ValidRAMaddr(addr: word): boolean; -{Indica si la dirección indicada es válida dentro del hardware del PIC} +{Indica si la dirección indicada es válida dentro del hardware del CPU} begin if addr > CPUMAXRAM then exit(false); //excede límite exit(true); @@ -1251,7 +1254,7 @@ begin comLat := ram[i].sideComment; comLin := ram[i].topComment; //Verifica si es variable - if ram[i].used = ruVar then begin + if ram[i].used in [ruData, ruAbsData] then begin //Escribe en forma de variable if incAdrr then begin if comLin<>'' then lOut.add(comLin); @@ -1314,7 +1317,7 @@ begin maxUsed := 0; //Busca dirección de inicio usada for i := 0 to CPUMAXRAM-1 do begin - if ram[i].used<>ruUnused then begin + if ram[i].used in [ruCode, ruData] then begin if i<minUsed then minUsed := i; if i>maxUsed then maxUsed := i; end; @@ -1338,7 +1341,7 @@ begin SetLength(ram, CPUMAXRAM); //inicia una configuración común ClearMemRAM; - SetStatRAM($020, $04F, cs_implemen); + SetStatRAM($020, $04F, cs_impleGPR); //Estado inicial iRam := 0; //posición de inicio @@ -1564,7 +1567,7 @@ begin PIC16InstName[i_TYA].name := 'TYA'; //Transfer Index Y to Accumulator PIC16InstName[i_TYA].AddAddressMode(aImplicit,$98,1,2,''); - PIC16InstName[i_Inval].name := 'Inval'; + PIC16InstName[i_Inval].name := 'Inv'; end;